2016-07-09 18 views
0

動的オプションを追加するために2つのテーブルビューを使用する必要があるページを作成しました。問題は、1つのテーブルだけがデータを表示し、もう1つはデータを表示しないことです。私はどこで間違っていたのですか?1つのUIviewcontrollerで2つのテーブルビューを追加する方法

私の見解のスクリーンショット。以下は

enter image description here

enter image description here

私のコード - を追加してい

@interface FlirtMatchViewController() 
{ 
    UILabel *headerTitle; 
    NSArray *tableData; 
    NSArray *arrimages; 
    NSArray *tableData1; 
    NSArray *arrimages1; 
} 
@end 

@implementation FlirtMatchViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    tableData = [NSArray arrayWithObjects:@"TattooSingles",@"Eyecatcher",@"Tattoo Toplist",@"Radar",@"Flirt Chat",@"Free VIP Membership",@"VIP Membership",@"Invite Friends",nil]; 

    arrimages = [NSArray arrayWithObjects:@"[email protected]",@"eye_catcher.png",@"tatto_toplist.png",@"radar.png",@"Flirt_chat.png",@"free_vip.png",@"vip_membership_navigation.png",@"add-friend1.png", nil]; 

    tableData1 = [NSArray arrayWithObjects:@"TattooSingles",@"Eyecatcher",@"Tattoo Toplist",@"Radar",@"Flirt Chat",@"Free VIP Membership",@"VIP Membership",@"Invite Friends",nil]; 

    arrimages1 = [NSArray arrayWithObjects:@"[email protected]",@"eye_catcher.png",@"tatto_toplist.png",@"radar.png",@"Flirt_chat.png",@"free_vip.png",@"vip_membership_navigation.png",@"add-friend1.png", nil]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if(tableView==_leftTableView) 
    { 
     return [tableData count]; 
    } 
    else { 
     return [tableData1 count]; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
    static NSString *CellIdentifier2 = @"Cell2"; 
    static NSString *CellIdentifier1 = @"Cell1"; 

    if(tableView==self.leftTableView) 
    { 
     static NSString *CellIdentifier1 = @"Cell1"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell == nil) 
     { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] ; 
     } 

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

     return cell; 
    } 
    else 
    { 
     static NSString *CellIdentifier2 = @"Cell2"; 

     UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 
     if (cell1 == nil) 
     { 
      cell1= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] ; 
     } 

     cell1.textLabel.text = [tableData1 objectAtIndex:indexPath.row]; 
     return cell1; 
    } 

} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    TattooSinglesScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:@"TattooSinglesScreen"]; 
    EyecatcherScreen *obj1=[self.storyboard instantiateViewControllerWithIdentifier:@"EyecatcherScreen"]; 
    TattooToplist *obj2=[self.storyboard instantiateViewControllerWithIdentifier:@"TattooToplist"]; 

    int i=indexPath.row; 

    if(i==0){ 
     [self.navigationController pushViewController:obj animated:NO]; 
    } 
    else if (i==1) { 
     [self.navigationController pushViewController:obj1 animated:NO]; 
    } 
    else if (i==2) { 
     [self.navigationController pushViewController:obj2 animated:NO]; 
    } 

} 

はまた、以下のコードを使用して、特定の画面に最初の3つのオプションをナビゲートしようとしています。しかし、コードは私のために働いていません。誰も私の疑問をクリアすることはできますか?

+0

あなたの2番目のテーブルビュー名 –

+0

_rightTableView –

+0

didSelectの 'if(tableView == self.leftTableView)'も追加していませんか? – iphonic

答えて

0

私はあなたがそれぞれのUITableViewのデータソースとデリゲートを処理するために別々のclasssesを作成する提案ができるが、単にそれぞれの新しいクラスにデータソースとデリゲートを割り当て、暗部が動作する提案は何

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
if (tableView == self. leftTableView) 
{ 
    return [tableData count]; 
} 

if (tableView == self. rightTableView) 
{ 
    return [tableData1 count]; 
} 


} 


-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{  
if(tableView==self.leftTableView) 
{ 
    static NSString *CellIdentifier1 = @"Cell1"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] ; 
    } 

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

    return cell; 
} 

if (tableView == self._rightTableView) 
{ 
    static NSString *CellIdentifier2 = @"Cell2"; 

    UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 
    if (cell1 == nil) 
    { 
     cell1= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] ; 
    } 

    cell1.textLabel.text = [tableData1 objectAtIndex:indexPath.row]; 
    return cell1; 
} 

} 
+0

任意のクエリ...... –

+0

まだ私のために働いていません:( –

+0

あなたは '_rightTableView'データソースの接続とcurrnet viewcontroller –

1

好きですテーブルビュー。これはより洗練され、あなたが持っている論理問題を解決するのに役立ちます。

ご質問やご不明な点がありましたら、このコメントをお寄せください。

+0

私はあなたが提案した通りに正確にやります。 –

関連する問題