2012-02-05 8 views
0

私はビューベースのアプリケーションを1つだけ持っています:TableViewに配列を表示しますが、動作しません。理由はわかりません。ここにコードがあります。UITableViewにテキストを表示できません

.h 

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{ 
    NSArray *array; 
    IBOutlet UITableView *table; 
} 

.m 

-(void)viewDidLoad{ 
[super viewDidLoad]; 
    array = [array initWithObjects:@"iPad", @"iTV", nil]; 

} 

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

- (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; 
} 

なぜTableViewにテキストが表示されないのですか?ありがとう、人々! NSIndexPathは "行" プロパティを持っていない

ARCの下

+0

をリリースし、それを保持するか、またはしたい場合に応じて、

[[NSArray alloc] initWithObjects:@"iPad", @"iTV", nil]; 

または

[NSArray arrayWithObjects:@"iPad",@"iTV",nil]; 

のいずれかである必要があり指摘しています'メソッドと呼ばれる? – barley

+0

申し訳ありませんが、viewDidLoadにありました。私はそれを編集するつもりです。 – Adri

答えて

2
array = [array initWithObjects:@"iPad", @"iTV", nil]; 

を試してみてください、あなたが実行していると仮定また、あなたが呼び出すことを確認してください

array = [NSArray initWithObjects:@"iPad", @"iTV", nil]; 

であるべき大麦を記載したarrayInit

編集: ヴィンスは右のそれはあなたが `arrayInitである場合、自動で

+2

は、[[NSArray alloc] initWithObjects:...]; 'または' [NSArray arrayWithObjects:...]; '? –

+0

はい、それはarrayWithObjectsでなければなりません...私はそれを忘れました。 – tassinari

+0

私は質問を編集するつもりです。*編集済み* – Adri

1

病気

NSInteger row = [indexPath indexAtPosition:1]; 
cell.textLabel.text = [array objectAtIndex:row]; 
+1

'NSIndexPath'は' UIKit'とリンクするときに 'row'プロパティを持ちます。 * [NSIndexPath UIKit追加リファレンス](https://developer.apple.com/library/ios/#documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/Reference.html#//apple_ref/doc/uid/TP40007175-CH3-DontLinkElementID_2 )* –

+0

クール。 –

関連する問題