누구나 내가 무엇을 잘못하고 있다고 말할 수 있습니까? 템플릿 '빈 응용 프로그램'을 선택하여 빠른 프로젝트를 만들었습니다. 하위 클래스 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 메서드가 전혀 호출되지 않습니다.
저는 아이폰 프로그래밍에 익숙해서 어쩌면 내가 잘못하고있는 걸까요?
나는 tableviewcontroller이
내가 몇 가지 더 테스트를 실시하고 있으며 그 ARC 내 문제를 일으킨 것 같다 만드는 문제 here을 기록했다. 내가 좋아하는 몇 가지 프로젝트를 만들었습니다
- 이 XIB과의 UIViewController 사용하여 테이블 뷰를 생성 XIB
- 않고있는 UIViewController 사용하여 테이블 뷰를 생성 컨트롤러
- 에 XIB없이 간단한보기 테이블을 생성
나는 테이블을 아래로 스크롤하려고했다. 각 경우에 프로그램이 충돌했다. 둘째, 대리자를 올바르게 설정했지만 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 –