私のUIViewnibファイルには、画面の約半分を占めるUITableViewがあります。対応する.hファイルと.mファイルは次のとおりです。
// helloViewController.h
#import <UIKit/UIKit.h>
@interface helloViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *locationArray;
}
@property (nonatomic, retain) NSArray *locationArray;
@end
// helloViewController.m
@synthesize locationArray;
- (void)viewDidLoad {
locationArray = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", nil];
[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];
}
[[cell textLabel] setText: [locationArray objectAtIndex:[indexPath row]]];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 8;
}
これを実行すると、テーブルをスクロールしようとするとクラッシュします(デバッガーでエラーは発生しません)。ただし、[[cell textLabel] setText:[locationArray objectAtIndex:[indexPath row]]];を置き換えると、と
[[cell textLabel] setText:@"Boom"];
...クラッシュしません...
この問題の原因は何ですか?デリゲートとデータソースはIBのファイルの所有者に接続されており、ファイルの所有者のクラスは正しいクラスに設定されています。ペン先のuiview内でテーブルビューを使用しているのは問題ですか?