2010-05-06 70 views
0

我想学习如何使用不同的视图,对于这个示例测试应用程序,我有一个登录页面,成功登录后,用户重定向到表视图,然后选择在表格视图中的项目中,用户被引导到显示项目细节的第三页面。Iphone SDK - 将UITableView添加到UIView

第一页工作得很好,但是当我进入第二页时,问题发生,所显示的表没有标题,我无法添加标题或工具栏或除表格本身内容以外的任何内容。当我点击该项目时,不用说没有任何反应。没有错误。

我对编程相当陌生,一直在Java上工作,但从来没有在C上(虽然我有一些C的基本知识),Objective C对我来说是新的。

这是代码。

-(IBAction) login { 

RootViewController *rootViewController = [[RootViewController alloc] init]; 

if([username.text isEqualToString:@"test"]&&[password.text isEqualToString:@"test"]){ 
[window addSubview:[rootViewController view]]; 

[window makeKeyAndVisible]; 
} 

else { 
    loginError.text = @"LOGIN ERROR"; 
    [window addSubview:[viewController view]]; 
    [window makeKeyAndVisible]; 
} 
} 

@interface RootViewController : UITableViewController { 

IBOutlet NSMutableArray *views; 
} 

@property (nonatomic, retain) IBOutlet NSMutableArray * views; 

- (void)viewDidLoad { 

views = [ [NSMutableArray alloc] init]; 

OpportunityOne *opportunityOneController; 

for (int i=1; i<=20; i++) { 
    opportunityOneController = [[OpportunityOne alloc] init]; 
    opportunityOneController.title = [[NSString alloc] initWithFormat:@"Opportunity %i",i]; 

    [views addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
         [[NSString alloc] initWithFormat:@"Opportunity %i",i], @ "title",      opportunityOneController, @"controller",      nil]]; 
    [email protected]"GPS"; 
} 

[super viewDidLoad]; 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell. 

cell.textLabel.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"]; 

return cell; 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"]; 

[[self navigationController] pushViewController:targetViewController animated:YES]; 

} 

哇,我发现真的很难发布代码。我为坏的格式道歉,但我无法超越这个文本编辑器的格式化规则。

感谢, 沙市

+0

这是太多的代码让人们看,更不用说重新格式化了。通过更简单的教程,学习缩小问题范围,只显示相关的代码。如果信息不够,人们会要求更多。 – DyingCactus 2010-05-07 02:05:35

+0

我想我已经删除了很多不必要的代码,让我知道如果我需要清理更多。 – Shashi 2010-05-07 05:15:52

回答

0

开始导航基础的应用。根据需要制作尽可能多的视图控制器(从上面3个)。根据需要将视图控制器从一个推到另一个。

+0

我想学习使用基于窗口的应用程序,我可以添加任何数量的简单按钮的简单意见,没有问题,但只有当我想创建一个UIView-> UITableView-> UIView我有问题。在第二个视图中,我所看到的只是表格,没有标题,没有任何工具栏。我可以创建一个基于导航的应用程序,我有一个UITableView - > UIView,它工作得很好。 – Shashi 2010-05-07 19:39:23