1
我很困惑,并尝试了很多不同的东西来消除我面临的错误。连接2个或更多的tableviews显示来自同一个nsarray的信息
我有一个NSArray的蛋白质,在我的故事板中我有两个独立的表格视图,我希望能够显示protiens数组。
我在 - (UITableViewcell *)和@end中有两个错误。
如果有人可以帮助请找我下面的代码ViewController.m:(请忽略接近尾声SEGUE编码)
#import "JViewController.h"
#import "OneViewController.h"
#import "TwoViewController.h"
@interface JViewController()
@end
@implementation JViewController
{
NSArray *proteins;
}
@synthesize tableView1;
@synthesize tableView2;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
proteins = [NSArray arrayWithObjects:@"Chicken", @"Turkey", @"Ham", @"Steak", @"Pork Chop", @"Roast Lamb", @"Salmon", @"Egg", @"Lentils", @"Kidney Beans", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == tableView1) {
return [proteins count];
{
if (tableView == tableView2) {
return [proteins count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ProteinCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView1 == tableView2)
{
proteins;
}
else
{
proteins;
}
cell.textLabel.text = [proteins objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showMealOneDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
OneViewController *destViewController = segue.destinationViewController;
destViewController.proteinName = [proteins objectAtIndex:indexPath.row];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
大三江源提前。