HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 添加TableView子视图崩溃应用程序大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试添加一个tableview,所以当有人按下某个按钮时,视图会切换到tableview,并有几个选项.

这是我的按钮代码

-(IBACtion)buttonPressed:(id)sender  
    {
         LevelChoice *level = [[LevelChoice alloc] initWithNibName:nil bundle:nil];
         [self.view addSubview:level.view];
         [level release];   
   }

以下是我的UITableViewController子类的代码片段:

LevelChoice.h
码:

@interface LevelChoice : UITableViewController {
    NSArray *choices; 
}

LevelChoice.m

码:

-(void)viewDidLoad
{ 
    choices = [[NSArray alloc] initWithObjects:@"Level 1",@"Level 2",@"Level 3",nil];

    [super viewDidLoad];

}

码:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
    return 3;
}

-(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];

     }
  cell.text = [choices objectATindex:indexPath.row];
  return cell;

}

有谁知道我错过了什么?

解决方法

区分控制器和视图.您可以

>或者使用presentModalViewController呈现UITableViewController:animated:或者使用pushViewController:animated:. (是的,在这种情况下你可以释放它.)>或者只是在现有视图控制器中保留UITableView,并根据需要使用隐藏属性显示或隐藏它.当然,您需要为表实现数据源和委托方法.

大佬总结

以上是大佬教程为你收集整理的iphone – 添加TableView子视图崩溃应用程序全部内容,希望文章能够帮你解决iphone – 添加TableView子视图崩溃应用程序所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。