2012-04-02 42 views
0

我對iPhone開發相對較新,我試圖添加uitableview來滾動視圖,但它顯示Sigabart錯誤,然後我以編程方式添加並添加了uitableviewdelegate和uitableview數據源給它,添加'noOfRowsInSection'方法的delgate方法不beeing called.c能夠幫助我。在滾動視圖中添加表視圖

@interface Class : UIViewController<UITableViewDelegate,UITableViewDataSource> { 
    UITableView *table; 
    UIScrollView *scrView; 
    NSArray *array; 
} 
@property (nonatomic, retain) IBOutlet UIScrollView *scrView; 
@end 

here is my implementation 

- (void)viewDidload 
{ 
    array = [[NSArray alloc]initWithObjects:@"harsha",@"theja",@"pandu", nil]; 
    [super viewDidUnload]; 
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 260, 360, 220)]; 
    [self.view addSubview:table]; 
    table.delegate = self ; 


} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [array count]; 
} 
- (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] autorelease]; 
    } 
    cell.textLabel.text = [array objectAtIndex:indexPath.row]; 
    return cell; 

} 

@end 

我加入雖然Interface Builder中滾動視圖,但我做的表格視圖編程的,matically的TABL視圖顯示在屏幕上,但該方法不beeing稱爲

+1

請向我們展示代碼和委託方法:)您是否在interfacebuilder中建立了連接? 控制檯用sigbart顯示的錯誤是什麼? – 2012-04-02 16:56:50

+0

這有很多可能的原因,如果沒有問題代碼幾乎不可能調試。 – mydogisbox 2012-04-02 17:01:31

+0

在附註上,UITableView是UIScrollView的子類。所以如果你只需要標準的垂直滾動,就使用UITableView。 – cobbal 2012-04-03 10:54:53

回答

3

1:您正在使用的,而不是viewDidLoad中viewDidUnload,

第二:增加tableview.dataSource = self並實現數據源委託方法= )

您正在使用委託而不是數據源=)

+0

謝謝你,我在視圖中只做了加載,但我還沒有將table.datasource添加到self.Adiing它解決了它。 – SreeHarsha 2012-04-03 11:02:38

+0

有時它很簡單=) 很高興我能幫上忙。 – 2012-04-03 11:30:34

1

你把你的代碼中viewDidUnload方法。將這段代碼viewDidLoad

- (void)viewDidUnload 
{ 
    array = [[NSArray alloc]initWithObjects:@"harsha",@"theja",@"pandu", nil]; 
    [super viewDidUnload]; 
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 260, 360, 220)]; 
    [self.view addSubview:table]; 
    table.delegate = self ; 
} 

應該是這樣:

- (void)viewDidLoad 
{ 
    array = [[NSArray alloc]initWithObjects:@"harsha",@"theja",@"pandu", nil]; 
    [super viewDidUnload]; 
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 260, 360, 220)]; 
    [self.view addSubview:table]; 
    table.delegate = self; 
    table.dataSource = self; 
} 
+0

我已經做到了在視圖中只加載,因爲你已經問過代碼,在我的應用程序中有不同的其他東西向你展示我已經創建了一個類,並粘貼在viewdidunload意外我真的很抱歉。 – SreeHarsha 2012-04-03 10:52:55

+0

閱讀我的答案:-)你忘了設置數據源。 – 2012-04-03 10:57:53

相關問題