1

テーブルビューに何も表示されていないので、コードに何が欠けているのか誰かに教えてもらえますか?また、デリゲートとデータソースがすでにコードで設定されており、UITableViewビューアウトレットがあります。

.h

@interface FoodViewController :  UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSMutableArray *objects;
}
@property (strong, nonatomic) IBOutlet UITableView *tablewviewFood;
@property (strong, nonatomic)  NSMutableArray *objects;
@end

.m

- (void)viewDidLoad
{
[super viewDidLoad];
objects =[[NSMutableArray alloc] initWithObjects:@"Employee Services",@"Human           Resources",@"Organization",@"Policies",@"Reference",nil];
 _tablewviewFood.dataSource = self;
  _tablewviewFood.delegate = self;

}

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

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

}

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

static NSString *CellIdentifier = @"Celler";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}

// Configure the cell...
cell.textLabel.text = [_objects objectAtIndex:indexPath.row];

return cell;
4

1 に答える 1

4

主な問題は、をviewDidLoad設定しますobjectsが、それnumberOfRowsInSectionを処理すること_objectsです。

.hファイルとすべてのプロパティおよびivarを確認せずに、という名前のプロパティと。という名前のivarを宣言したと推測する必要がありobjectsますobjects。ただし、暗黙的または明示的なのいずれかを使用しています@synthesize objects = _objects

これにより、2つのivar、objectsおよびが作成され_objectsます。

プロパティを宣言しますが、ivarと。の両方を削除し@synthesizeます。次に、コードでは常にを使用しますself.objects

更新:はい、新しく投稿されたコードに基づいて、私は正しかったです。

于 2013-03-02T18:48:28.457 に答える