开发者

UITableView crashes when datasource is connected in Interface Builder

- (NSInteger)numberOfSectionsInTableView:(UITableView *)cijferTableView{
return 1;
}
- (NSInteger)cijferTableView:(UITableView *)cijferTableView numberOfRowsInSection:(NSInteger)section {
    return [marksArray count];
}
- (UITableViewCell *)cijferTableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)ind开发者_运维百科exPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [marksArray objectAtIndex:indexPath.row];

return cell;
}

I have a marksArray which is filled with strings. The code worked fine until a quarter of an hour ago but since then it has been crashing when I load the view this code is in, without me changing anything.

When I, in interface builder, disconnect the datasource however, the view is loaded properly without a crash. But of course, it won't fill the table in that case.

What did I do wrong?


Update:

The error the console gives is terminate called after throwing an instance of 'NSException'

Also, i didnt exactly add anything into marksArray just yet. To test, i just have this:

 //.h

NSMutableArray *marksArray;

and

//.m

marksArray = [NSMutableArray arrayWithObjects:@"1", @"2", nil;


It looks like you did a search and replace for "tableView" with cijferTableView and in doing so you renamed the methods, which will cause this to break. For example:

- (NSInteger)cijferTableView:(UITableView *)cijferTableView numberOfRowsInSection:(NSInteger)section {
    return [marksArray count];
}

should be...

- (NSInteger)tableView:(UITableView *)cijferTableView numberOfRowsInSection:(NSInteger)section {
    return [marksArray count];
}


1) You forgot to retain marksArray

2) Weird names for dataSource methods ('cijfer' stuff instead of tableView:numberOfRowsInSection: and tableView:cellForRowAtIndexPath:). They will not work.


Why are you renaming your delegate methods? Maybe those are causing some of your problems?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜