0

私はUIButtonと呼ばれていUploadButtonます。私はそれをクリックしたときに起こるはずのアクションを処理する次のコード行を使用しています::

-(IBAction)UploadButtonPressed:(id)sender{  

self.Upload = [[UploadSpaceTableViewController alloc] 
                         initWithStyle:UITableViewStylePlain];
self.UploadTableViewPopover = [[UIPopoverController alloc] 
                                initWithContentViewController:Upload];               

[self.UploadTableViewPopover presentPopoverFromBarButtonItem:sender 
                                permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

ここに、UploadSpaceTableViewController私が作った別のクラスがあります。次の機能があります::

- (void)viewDidLoad
{
[super viewDidLoad];


self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0);
self.keys1 = [NSMutableArray array];
[keys1 addObject:@"Red"];
[keys1 addObject:@"Green"];
[keys1 addObject:@"Blue"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [keys1 count];
}

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

// Configure the cell...

NSString *key1 = [keys1 objectAtIndex:indexPath.row];
cell.textLabel.text = key1;

return cell;
}

基本的に、私が欲しいのは私のクリックでUItableView内部を表示することです。UIPopOverControllerUploadButton

ただし、上記のコード行を実行すると、gdb::で次のエラーが発生します。

splitView[4486:f803] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
2012-06-27 14:05:05.531 splitView[4486:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:

UITableView内を表示しようとするのはこれが初めてですUIPopoverController。コードのバリエーションをたくさん試しましたが、整理できません。誰かが私を助けることができますか?ありがとう、よろしく。

4

4 に答える 4

0

あなたはあなたのセルを割り当てましたか私はあなたのコードによってそれがnillを返すと思います

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

 if(cell == nill){
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];  
}     
 // Configure the cell...

 NSString *key1 = [keys1 objectAtIndex:indexPath.row];
 cell.textLabel.text = key1;

 return cell;
}

これがあなたを助けるかもしれません...

于 2012-06-27T08:59:43.600 に答える
0

cellForRowAtIndexPathで次のコードを使用します。

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...

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

    NSString *key1 = [keys1 objectAtIndex:indexPath.row];
    cell.textLabel.text = key1;

    return cell;

}

これはあなたに役立つかもしれないと思います。

于 2012-06-27T09:01:01.153 に答える
0

問題は次の行です。

self.keys1 = [NSMutableArray array];

メソッドsetKeys UploadSpaceTableViewController/プロパティキーがありません。

2番目のエラーメッセージを編集します。

UITableView dataSourceは、tableView:cellForRowAtIndexPathからセルを返す必要があります。

UITableViewDataSourceこれは、メソッドを実装する必要があることを意味しますtableView:cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //configure your cell here

    return myCongiuredTableViewCell;
}
于 2012-06-27T08:33:32.793 に答える
0

このエラーは、keys1に値を割り当てるときに無効な引数を渡していることを意味しますself.keys1 = ...。たとえば、NSMutableArrayをNSDictionaryプロパティに渡す場合、そのエラーが発生します。

于 2012-06-27T08:34:39.690 に答える