UIViewController
onのメソッドを実装するために使用したいものがありますUITableViewDataSource
。私はこのヘッダーを持っています、FriendsController.h
:
#import <UIKit/UIKit.h>
@interface FriendsController : UIViewController <UITableViewDataSource>
@end
編集:@interface
宣言を次のように更新しました:
@interface FriendsController : UIViewController <UITableViewDataSource, UITableViewDelegate>
そしてこの実装、FriendsController.m
:
#import "FriendsController.h"
@implementation FriendsController
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(@"CALLED .numberOfRowsInSection()");
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"CALLED cellForRowAtIndexPath()");
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"FriendCell"];
cell.textLabel.text = @"Testing label";
return cell;
}
@end
実行すると、これは私に' -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x81734d0
'を与えます。誰かが私の実装/宣言に何か問題があるかどうかを確認できます.numberOfRowsInSection()
か?
編集:ここからメソッドリストの手法を追加し、ビュー'unconnected'を実行すると、次のリストが出力されます。
[<timestamp etc>] Method no #0: tableView:numberOfRowsInSection:
[<timestamp etc>] Method no #1: tableView:cellForRowAtIndexPath:
[<timestamp etc>] Method no #2: numberOfSectionsInTableView:
[<timestamp etc>] Method no #3: tableView:didSelectRowAtIndexPath:
[<timestamp etc>] Method no #4: viewDidLoad
スクリプトを投稿する: @ThisDarkTaoと@Peiの両方が正しく理解しました。これは、視覚的な部分を文書化した以前の質問に見られるように、ここにあります。