誰かが私に何かを教えてもらえますか? テンプレート「空のアプリケーション」を選択して、クイックプロジェクトを作成しました。 サブクラスUITableViewControllerで新しいコントローラを作成しました。xcode 4.2ではUITableViewControllerが正しく動作しませんか?
私は、コントローラを呼び出すためにコードの一部の下に書いている:
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// self.window.backgroundColor = [UIColor whiteColor];
MyTableViewController *mtvc = [[MyTableViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] init];
[nav pushViewController:mtvc animated:YES];
[self.window addSubview:nav.view];
[self.window makeKeyAndVisible];
return YES;
}
、それが動作しているかどうかを確認するためのUITableViewControllerのメソッドを埋める:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.text = @"test";
return cell;
}
セルテーブルを選択しようとすると、 didSelectRowAtIndexPathメソッドはまったく呼び出されません。
私はiPhoneのプログラミングで新しくて、多分私は何か間違っているのですか?
私はさらにいくつかのテストを実施してきたし、ARCは私の問題を引き起こしているようですtableviewcontroller
を作成すると、問題hereを掲載しています。 XIB でのUIViewController使用してテーブルビューを作成
- :私のようないくつかのプロジェクトを作成しました
テーブルを下にスクロールしようとしましたが、いずれの場合もプログラムがクラッシュしました。 第二に、私はデリゲートを適切に設定しましたが、メソッドdidSelectRowAtIndexPathを使用することはできません。データソースメソッドがうまく機能していると考えられます。
テーブルセルをスクロールしようとしたときにプログラムがクラッシュした後のスタックです。
> (gdb) bt > #0 0x0156009b in objc_msgSend() > #1 0x07821800 in ??() > #2 0x000ad589 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]() > #3 0x00098dfd in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:]() > #4 0x000a7851 in -[UITableView layoutSubviews]() > #5 0x00052322 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:]() > #6 0x013bde72 in -[NSObject performSelector:withObject:]() > #7 0x01d6692d in -[CALayer layoutSublayers]() > #8 0x01d70827 in CA::Layer::layout_if_needed() > #9 0x01cf6fa7 in CA::Context::commit_transaction() > #10 0x01cf8ea6 in CA::Transaction::commit() > #11 0x01d9237a in CA::Display::DisplayLink::dispatch() > #12 0x01d921af in CA::Display::TimerDisplayLink::callback() > #13 0x01390966 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__() > #14 0x01390407 in __CFRunLoopDoTimer() > #15 0x012f37c0 in __CFRunLoopRun() > #16 0x012f2db4 in CFRunLoopRunSpecific() > #17 0x012f2ccb in CFRunLoopRunInMode() > #18 0x012a5879 in GSEventRunModal() > #19 0x012a593e in GSEventRun() > #20 0x00013a9b in UIApplicationMain() > #21 0x00002588 in main (argc=1, argv=0xbfffed80) at /Users/lsd/Development/iPhone/MyTableView/MyTableView/main.m:16 > #22 0x000024e5 in start() (gdb)
私はその後、すべてが魔法のように作業を開始、未確認のARCと同じコード行で同じプロジェクトを作成しました。
ジョン
私はuがこの委任 を逃していると思う
デリゲートを適切にUITableViewControllerに設定してください。 self.tableView。デリゲート=自己; UITableViewControllerがに準拠していることを確認してください –
テーブルビューのデリゲートを設定しましたか? –
私はUITableViewControllerのviewDidLoadメソッドでデリゲートを設定しようとしました。私が間違っている場合は私を修正しますが、コントローラにself.tableView.delegateを設定することは悪い考えではありませんか?ビューで何とか設定してはいけませんか?私にとっては、dataSourceが正常に動作していることが少し奇妙です。 私を助けてくれてありがとう。 John –