私は文字通り、tableView を正しく実装しようと 20 時間以上試みてきました。スタック オーバーフローについていくつか質問し、他の多くの質問や同様の問題に関するフォーラムの質問を調べました。私が得た最も近いものは、空のtableViewを持つ実行中のプログラムです。私は目的cに非常に不満を感じています。
テキストビューとボタンから追加されたデータを含む可変配列をロードした単一のテーブルビューの例を誰かが投稿できますか? これは私の役に立たないコードの 1 つの変形です...次のエラーで実行されていません:
2013-06-10 11:42:05.939 WIDMIR Sign-In[32878:11303] *** Terminating app due to
uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7517c00>
setValue:forUndefinedKey:]: this class is not key value coding-compliant for
the key add.'
*** First throw call stack: (0x1c93012 0x10d0e7e 0x1d1bfb1 0xb7ce41 0xafe5f8 0xafe0e7
0xb28b58 0x232019 0x10e4663 0x1c8e45a 0x230b1c 0xf57e7 0xf5dc8 0xf5ff8 0xf6232 0x453d5
0x4576f 0x45905 0x4e917 0x231b 0x12157 0x12747 0x1394b 0x24cb5 0x25beb 0x17698 0x1beedf9
0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1317a 0x14ffc 0x1f5d 0x1e85)
libc++abi.dylib: terminate called throwing an exception (lldb)
.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
UITableView *tableView;
}
- (IBAction)add:(id)sender;
@property (nonatomic, retain) NSMutableArray *currentNames;
@property (weak, nonatomic) IBOutlet UITextField *name;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
.m:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize name;
@synthesize currentNames;
@synthesize tableView = _tableView;
- (void)viewDidLoad
{
self.currentNames = [[NSMutableArray alloc] init];
[super viewDidLoad];
UITableView *tv = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
self.tableView = tv;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [currentNames count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [currentNames objectAtIndex:indexPath.row];
return cell;
}
- (IBAction)add:(id)sender {
[currentNames addObject:[name text]];
[tableView reloadData];
name.text=@"";
}
@end