2012-12-21 66 views
0

我建立使用的UITabBarController簡單的數據添加應用程序,從firstviewcontroller數據存儲和通過customcell secondviecontroller顯示,但是當我選擇從的TabBar secondviewcontroller數據未顯示的問題被存儲。如何解決這個問題?iPhone應用程序查詢

這裏是FirstViewController對通DataArray中以secondviewcontroller編碼。

SecondViewController *svc = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; 
     [self presentModalViewController:svc animated:YES]; 

    finalArray = [[NSMutableArray alloc]init]; 

    [finalArray addObject:DataDic]; 

    svc.dataArray = [[NSMutableArray alloc]initWithArray:finalArray]; 
} 

和Secondcontroll.m文件編碼。

#import "SecondViewController.h" 
    #import "SaveDataCell.h" 

@implementation SecondViewController 
@synthesize Dict1,dataArray,btninfo,btnBack; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Second", @"Second"); 
     self.tabBarItem.image = [UIImage imageNamed:@"second"]; 
    } 
    return self; 
} 



- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    Dict1 = [[NSMutableDictionary alloc]init]; 



    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
// dataArray = [[NSMutableArray alloc]init]; 

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

- (void)viewDidAppear:(BOOL)animated 
{ 


[super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 
} 
- (NSInteger)numbe 

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

ew:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return[dataArray count]; 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 150; 
} 

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

    SaveDataCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = (SaveDataCell*)[[[NSBundle mainBundle] loadNibNamed:@"SaveDataCell" owner:self options:nil] objectAtIndex:0]; 
    } 


    cell.lblName.text = [[dataArray objectAtIndex:indexPath.row]valueForKey:@"Name"]; 
    cell.lblEmail.text = [[dataArray objectAtIndex:indexPath.row]valueForKey:@"Email"]; 
    cell.lblNo.text = [[dataArray objectAtIndex:indexPath.row]valueForKey:@"No"]; 
    cell.lblCity.text = [[dataArray objectAtIndex:indexPath.row]valueForKey:@"City"]; 
    cell.saveimg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[[dataArray valueForKey:@"Image"]objectAtIndex:indexPath.row]]]; 
    return cell; 
} 
-(IBAction)ClicktoBack:(id)sender 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 
-(IBAction)ClicktoInfo:(id)sender 
{ 

} 

回答

0

試試這個:

SecondViewController *svc = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; 

finalArray = [[NSMutableArray alloc]init]; 

[finalArray addObject:DataDic]; 

svc.dataArray = [[NSMutableArray alloc]initWithArray:finalArray]; 

[self presentModalViewController:svc animated:YES]; 
1

您可以通過在severl方法視圖控制器之間的數據。

//爲lowerVersions:

SecondViewController *tmpNamesListVC = [self.tabBarController.viewControllers objectAtIndex:1]; 
    [tmpNamesListVC yourArray]= self.arraytoPass; 
//

更高的版本

SecondViewController *tmpNamesListVC = [self.tabBarController.viewControllers objectAtIndex:2]; 
[tmpNamesListVC yourArray]= self.arraytoPass; 

而且你必須改變你的編碼

SecondViewController *svc = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; 

finalArray = [[NSMutableArray alloc]init]; 

[finalArray addObject:DataDic]; 

svc.dataArray = [[NSMutableArray alloc]initWithArray:finalArray]; 

[self presentModalViewController:svc animated:YES]; 
+0

的Secondone是Samething這CRDave解釋 –

0

製作的順序屬性在您的SecondViewController中..如下所示: -

@property(strong,nonatomic)NSMutableArray * array; 

和「@synthesize」它在「.m」文件中。現在

時,你會從 「FirstViewController」 導航..做到這一點: -

SecondViewController *svc = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; 

finalArray = [[NSMutableArray alloc]init]; 

[finalArray addObject:DataDic]; 

svc.array = finalArray 

[self presentModalViewController:svc animated:YES];