、次の行を追加します。
@interface YourClass: UIViewController <**UITableViewDataSource, UITableViewDelegate**>
右クリック(またはCtrlキーを押しながらクリック)し、tableViewからファイルの所有者に2回ドラッグします。一度、 "委任"を選択し、一度 "データソース"を選択します。
次に、あなたの.mファイルには、次を実装する必要があります:あなたの作業のtableViewを取得する必要があります
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return someNumber;}
- (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];
}
[[cell textLabel] setText:yourText];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//do what you want to with the information at indexPath.row
}
。
"UITableViewは機能していません" .... *動作していないのは何ですか? –
最初に私はxibとビルドにUITableViewを追加するだけで、私はテーブルビューをスクロールしようとしても何も起こりません! – Mateus
いくつかのコードを共有できますか?具体的には、tableviewのデータソースとデリゲートのコールバック? – bryanmac