切片UITableViewController的问题

时间:2011-07-06 04:24:25

标签: iphone objective-c uitableview

我有一个扩展UITableviewController的类,它显示一个名为“GigData”的数据类型(现在只包含字符串)。内容存储在“data”中,这是一个NSMutableArray,包含包含“GigData”的NSMutableArrays。这个数组被传递给我的类的实例,数组里面的数组组成了表的各个部分。这是我到目前为止实现的代码:

@synthesize data = _data;

- (id)init
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    _data = [[NSMutableArray alloc] init];
    [[self navigationItem] setTitle:@"Gigs by Date"];

    return self;
}

- (id)initWithStyle:(UITableViewStyle)style
{
    return [self init];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return [_data count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [[_data objectAtIndex:section] count];
}

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

    NSMutableArray *sectionArray = [_data objectAtIndex:[indexPath section]];
    GigData *gig =[sectionArray objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:[gig description]];

    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    GigData *temp = [[_data objectAtIndex:section] objectAtIndex:0];
    return [temp date];
}

当我运行应用程序时,我可以看到所有内容都分组到正确的组中,并且所有显示都是正确的,除了最后一节,它不断更改名称,其中一些包括“cs.lproj”,“headers”和“方法不允许”。滚动到表格底部然后向顶部崩溃应用程序。另外,如果我为“GigData”的描述提供我自己的实现,应用程序崩溃甚至更糟,我根本无法滚动到第二部分。数据在头文件中声明为属性,并设置为非原子并保留。我也尝试使用init方法中的代码在这个类中创建数据数组,但这没什么区别。应用程序的一些运行表明tableView中有一个问题:cellForRowAtIndexPath:当我创建“sectionArray”时。有没有人对我做错了什么有任何建议?

0 个答案:

没有答案