2011-09-15 4 views
0

아이폰을 처음 접했고 tableview에 텍스트를 표시하는 데 도움이 필요합니다. 여기 아이폰의 tableView에 텍스트가 없습니다.

내 코드입니다 :

.h 

@class MainMenuViewController; 

@interface RecherchePartenaireViewController : UIViewController <UINavigationControllerDelegate> { 

    MainMenuViewController *mainMenuViewController; 

    UINavigationController *navigationController; 

    GradientButton *rechercheButton; 

    RecherchePartenaireResultatListeViewControleur *recherchePartenaireResultatListeViewControleur; 

    IBOutlet UITableView *categorystable; 
    NSMutableArray *listData; 
} 

@property (nonatomic, retain) IBOutlet MainMenuViewController *mainMenuViewController; 

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 

@property (nonatomic, retain) IBOutlet GradientButton *rechercheButton; 

@property (nonatomic, retain) IBOutlet RecherchePartenaireResultatListeViewControleur *recherchePartenaireResultatListeViewControleur; 

@property (nonatomic, retain) IBOutlet UITableView *categorystable; 
@property(nonatomic, retain) NSArray *listData; 

@end 

와하는 .m에 내가 가진 내 실수

@synthesize mainMenuViewController, navigationController, rechercheButton, recherchePartenaireResultatListeViewControleur,listData; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)dealloc 
{ 

    [mainMenuViewController release]; 
    [navigationController release]; 
    [rechercheButton release]; 

    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    listData = [[NSMutableArray alloc] initWithObjects:@"iPhone", @"iPod", @"iPad",nil]; 
    NSLog(@"hey %@",listData); 

    [rechercheButton useRedDeleteStyle]; 

    // Do any additional setup after loading the view from its nib. 

} 

- (void)viewDidUnload 
{ 
    self.rechercheButton = nil; 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 


    } 

    // Set up the cell... 
    cell.textLabel.text = @"label"; 

    /*[[cell textLabel] setText: [[listData objectAtIndex:indexPath.row] valueForKey:@"name"]];*/ 


    return cell; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return listData; 
} 

@end 

을 내가 tableView.Where에 아무 것도 얻을 수 없다? 나는 그물에 많은 예제를 보았으나 내가 잘못한 것을 볼 수 없다. 누구든지 나를 도울 수 있습니까?

+2

Xib 파일에서 viewController로 tableView의 delegate와 dataSource를 설정 했습니까? – Zoleas

+0

고마워요 ... 그게 문제 였어요 ... 고마워요 :) – Gabrielle

+0

대답으로 쓰길 원하나요? 당신이 그걸 받아 들일 수있을 겁니다. – Zoleas

답변

3

, 당신이 대리자를 설정하고는 dataSource 당신의 ViewController로 당신의있는 tableView의 있나요?

1

tableView가 표시되지만 셀/내용이 표시되지 않는다면, 값을 설정할 수도 있습니다.

EDIT : 행 높이를 44px로 설정하는 m.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
return 44.0; 
} 

그 방법에 대한 listData 대신 [listData count]를 반환해야하는 다른 대답에 동의합니다.

+0

당신은 더 명백 할 수 있습니까? 이 줄을 .m에 넣으면 되죠? – Gabrielle

+0

내 편집 Gabrielle을 확인하십시오. – Madhu

+0

는 동일합니다. (.. – Gabrielle

2

당신이 당신의 UITableView 세포의 표준 스타일을 사용하려는 경우, 당신은 예를 들어,이 새로운 세포를 만드는 라인을 교체해야합니다 :

교체

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

셀에 대해 미리 정의 된 다른 스타일을 선택할 수도 있습니다. UITableViewCellStyleDefault, UITableViewCellStyleValue1, UITableViewCellStyleValue2, UITableViewCellStyleSubtitle

또한 오류 번호가 numberOfRowsInSection:입니다. 다음과 같이 변경해야합니다 :

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section   
{ 
    return [listData count]; 
} 
+0

을 입력합니다. ** cell = [[UITableViewCell alloc] initWithFrame : CGRectZero reuseIdentifier : CellIdentifier] [listData count]하지만 tableview는 비어 있습니다. 셀은 보이지만 아무것도 표시되지 않습니다. – Gabrielle

+0

눈치 채신 선을 바꿨습니까 ??? – Nekto

2

다음과 같이 변경해야합니다.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    listData = [[NSMutableArray alloc] initWithObjects:@"iPhone", @"iPod", @"iPad",nil]; 
    NSLog(@"hey %@",listData); 

    [rechercheButton useRedDeleteStyle]; 

    // Do any additional setup after loading the view from its nib. 

    [categorystable reloadData]; 
} 

또한 변경됩니다. 이 같은

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [listData count]; 
} 
2

변경,

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [listData count]; 
} 
1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     return [listData count];//that many times cellFoeRowAt Index method Called. 
    } 
    in above case you are returning Array instead OF Count. 

환호

당신의 XIB 파일에서
관련 문제