1

を入力する必要があるtableViewがありますNSMutableArray。これは、カスタム プロトタイプがなくても問題なく機能しましたUITableViewCell。という名前のセル用の独自のファイルがありますSimpleTableCell。ストーリーボードのプロトタイプ セルには、このクラスが割り当てられています。SimpleTableCell.hの内容 :

#import <UIKit/UIKit.h>

@interface SimpleTableCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic, weak) IBOutlet UILabel *moreInfoLabel;
@end

viewControllerこれは、次のように、私が持っている場所にインポートされtableViewます: CargoViewController.h

#import <UIKit/UIKit.h>
#import "StartupViewController.h"
#import "boatInfoViewController.h"
#import "SimpleTableCell.h"

@interface CargoViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UITableViewDelegate, UIPickerViewDataSource>

@property(strong,nonatomic) IBOutlet UILabel *testLabel; //label I use to test stuff instead of LOG
@property(strong,nonatomic) IBOutlet UIButton *findOwner; //button to summon pickerWheel
@property(strong,nonatomic) IBOutlet UIButton *findShip; //Button to confirm selection in picker and unhide tableView
@property(strong,nonatomic) NSArray *boatOwners; //Array for boat owners.
@property(strong,nonatomic) NSMutableArray *boatsForOwner; //array for boats, added by owner
@property(strong,nonatomic) IBOutlet UITableView *boatsTableView; //Table view
-(IBAction)findOwnerButtonPressed:(id)sender;
-(IBAction)findShipButtonPressed:(id)sender;
@property(strong, nonatomic) IBOutlet UIPickerView *shipOwners; //ship owner picker wheel
@property(strong,nonatomic)IBOutlet UILabel *infoLabel;
/*@property(strong,nonatomic)IBOutlet UILabel *nameLabel; //These was tested, but didn't work. Illegal assignment error.
@property(strong,nonatomic)IBOutlet UILabel *moreInfoLabel;
@property(strong,nonatomic)IBOutlet UITableViewCell *SimpleTableCell;*/

@end

これも、 CargoViewController.mへの制御です(関連する部分のみが追加されています) 。

#import "CargoViewController.h"
#import "SimpleTableCell.h"
@interface CargoViewController ()


@end

@implementation CargoViewController
@synthesize testLabel, findOwner, findShip,shipOwners, boatsTableView, infoLabel;
@synthesize boatOwners, boatsForOwner;

//When I try to synthesize name and infolabel in cell here, it does not work

//...more code...

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

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

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

cell.nameLabel.text = [boatsForOwner objectAtIndex:indexPath.row];
return cell;
}

私の問題は次のとおりです: cell.nameLabel.textオブジェクトに見つかりません。私のストーリーボードUITableViewCell によると、どちらここに画像の説明を入力が間違っています(?)

詳細については、プロトタイプ セルを実装する前にテーブルが機能していたことを確認してください。デフォルトを使用する前に。エラー トリガー:

#pragma mark -
#pragma mark PickerView DataSource

- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [boatOwners count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
         titleForRow:(NSInteger)row
        forComponent:(NSInteger)component
{
return [boatOwners objectAtIndex:row];
}


#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component
{
NSString *boatsFromOwner = [boatOwners objectAtIndex:[shipOwners selectedRowInComponent:0]];
//if(boatsForOwner) {[boatsForOwner release]; boatsForOwner = nil;}
boatsForOwner = [[NSMutableArray alloc] init];
if ([boatsFromOwner isEqualToString:@"Owner1"]) {
    [self.boatsForOwner addObject:@"Titanic1"];
    [self.boatsForOwner addObject:@"Titanic2"];
    [self.boatsForOwner addObject:@"Titanic3"];
    [self.boatsForOwner addObject:@"Titanic4"];
    [self.boatsForOwner addObject:@"Titanic5"];
    [self.boatsForOwner addObject:@"Titanic6"];
    [self.boatsForOwner addObject:@"Titanic7"];

}
NSLog(@"%@",boatsFromOwner);

[boatsTableView reloadData];

}
4

2 に答える 2

1

この行を変更します。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

このため:

SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

ちなみに、ストーリーボードを使用すると、tableView:dequeueReusableCellWithIdentifier:が返されませんnil

于 2013-01-11T11:29:43.520 に答える
0
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

に変更してみてください

SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
于 2013-01-11T11:33:13.627 に答える