2012-04-19 4 views
1
좀 다른 배열을 내있는 ScrollView에 4 UITableViews를 추가하고 poppulate 할

에서 tableviews을 채우는 방법 (의 내가 각각 하나 개의 배열이 있다고 가정하자). 나는이 scrollview를 내 self.view에 추가했다. (UIViewController 클래스에서이 일을한다.) 아무도 도와 줄 수있는 내 Tableviews 채울 수 있습니까?의 UIViewController

일부 상세 정보 : 여기

이 스크린 샷; 여기 enter image description here

내 UIViewControllerClass의 인터페이스가

#import <UIKit/UIKit.h> 

@interface MainMenu : UIViewController<UITableViewDelegate> 

@property (retain, nonatomic) IBOutlet UIScrollView *scrollView; 
@property (retain, nonatomic) IBOutlet UITableView *group1; 
@property (retain, nonatomic) IBOutlet UITableView *group2; 
@property (retain, nonatomic) IBOutlet UITableView *group3; 
@property (retain, nonatomic) IBOutlet UITableView *group4; 

@end//i drag/dropped from IB, so there is no problem with synthesizes.. 

내가 다른 배열과 함께이있는 tableview을 채우려 어떻게이 상황을 처리하는 것입니다 ..? 덕분에 많은

추가 참고; .. 그 후 각 테이블에 대해 다른 태그를 할당합니다, 먼저 4 개 테이블의 UIViewController에 드 위임 및 데이터 소스를 만들 것입니다,

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

    UITableViewCell *cell = [group1 dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil]; 
    cell.textLabel.text = [array objectAtIndex:indexPath.row]; 
    return cell; 

} 
+1

당신은 인터페이스에서 데이터 소스를 입력하지 않은 당신은 또한 방법을 구현해야합니다 : - (NSInteger)있는 tableView : (jQuery과 *)있는 tableView numberOfRowsInSection : (NSInteger) 섹션; – WhiteTiger

답변

1

친구 다음을 : 나는이 같은 있지만 효과 시도 대리인 및 데이터 소스 프로토콜을 추가합니다 ... 당신 같은이 테이블보기의 태그를 테스트 할 수 있도록 당신은 정상적인있는 UITableViewController처럼 ...이 모든 방법이 jQuery과 매개 변수를받을 데이터 소스 위임 메소드를 구현합니다

... 

if (tableView.tag == 10) { 
//implement the table 1 
NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil]; 
cell.textLabel.text = [array objectAtIndex:indexPath.row]; 

} else if (tableView.tag == 20) { 
//implement the table 2 
} else if (tableView.tag == 30) { 
//implement the table 3 
} else if (tableView.tag == 40) { 
//implement the table 4 
} 

return cell; 

모든 테이블보기를 할 같은 방법을 사용합니다 이런 식으로 ..

+0

그러나 구현 방법 - (NSInteger) tableView : (UITableView *) tableView numberOfRowsInSection : (NSInteger) 섹션 { } 스위치() - 사례를 받아 들일 수 없습니다. – ilhnctn

+0

다시 테이블보기를 테스트하고, 필요하면 다시 if를 사용하십시오 ... –

+0

내가 문제를 해결, 그것은 많은 (당신이 말한대로 내가 태그를 사용) – ilhnctn