0

TableViewを作成し、NSArrayからデータを入力しようとしています。ただし、次のエラーが発生します。

2012-12-21 15:53:10.239 Arr[13219:c07] -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x71ccb60
2012-12-21 15:53:10.240 Arr[13219:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x71ccb60'
*** First throw call stack:
(0x1c90012 0x10cde7e 0x1d1b4bd 0x1c7fbbc 0x1c7f94e 0x1f96e8 0x1fc3c4 0xc0fa2 0xc092c 0xc4426 0xc90ce 0x6592d 0x10e16b0 0x228cfc0 0x228133c 0x228ceaf 0x1048cd 0x4d1a6 0x4bcbf 0x4bbd9 0x4ae34 0x4ac6e 0x4ba29 0x4e922 0xf8fec 0x45bc4 0x45dbf 0x45f55 0x4ef67 0x12fcc 0x13fab 0x25315 0x2624b 0x17cf8 0x1bebdf9 0x1bebad0 0x1c05bf5 0x1c05962 0x1c36bb6 0x1c35f44 0x1c35e1b 0x137da 0x1565c 0x1c2d 0x1b55 0x1)
libc++abi.dylib: terminate called throwing an exception

どのコードがこれを引き起こしているのかよくわからないので、2つのテーブルメソッドを添付します。

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    return cell;
}

NSArrayの作成:

@implementation ArrViewController {
    NSArray *tableData;
}

@synthesize itemTxt = _itemTxt;
@synthesize itemsLabel = _itemsLabel;
@synthesize model = _model;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
}
4

2 に答える 2

3

テーブル ビューのデータ ソースが正しく設定されていません。これにより、tableView:numberOfRowsInSectionメッセージが間違ったオブジェクトに送信されます。これはUIView、エラー メッセージに表示されるとおりです。

 [UIView tableView:numberOfRowsInSection:]

dataSourceプロパティを設定したコードを確認/投稿して、UITableView何が問題なのかを確認してください。間違ったオブジェクトを渡している可能性があります。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionデータソースは、投稿に従ってクラスを定義するオブジェクトそのものです。

于 2012-12-21T15:06:15.163 に答える
0

あなたの.hファイルで次のコードを使用してください

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *your_Table;

あなたの.mファイルで

@implementation ViewController
@synthesize your_Table;

Xibファイル内DelegateおよびdataSourceに接続しますFileowner

またはプログラムでViewDidLoad割り当てます

your_Table.delegate=self;
your_table.dataSuorce=self;

その後、これを使用します

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

それがあなたを助けることを願っています。

そうでない場合は、.h ファイルからコードを投稿します。

于 2012-12-21T15:12:21.957 に答える