iPhone应用查询

标签 iphone objective-c ios

我正在使用UITabBarController构建简单的数据添加应用程序,来自firstviewcontroller的数据通过customcell存储并显示在secondviecontroller上,但问题是当我从选项卡栏选择secondviewcontroller时,存储的数据没有显示。如何解决这个问题?

这里是 FirstViewController 将数据数组传递给 secondaryviewcontroller 的代码。

 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
{

}

最佳答案

您可以通过多种方法在 View Controller 之间传递数据。

喜欢

//对于较低版本:

 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];

关于iPhone应用查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13991738/

相关文章:

ios - 如何制作自定义 TableView ,其中如果行是一个 TableView 也显示为一行表

ios - 为什么我在 Objective-C 中的枚举上收到类型冲突警告?

ios - GLKit.framewok 与 OpenGLES.framework 与 QuartzCore.framework

ios - Swift,我想从设备获取电话号码(不是 udid)和电子邮件

iphone - Apple 怎么知道你在使用私有(private) API?

ios - 首次使用 iOS 发送 facebook 应用邀请不显示应用邀请对话框

ios - 解析 SDK 和 Swift : Incorrect argument label in call PFObject 'withoutDataWithObjectId'

iphone - 旧 iphone 3g 上的 HTTPS 请求

iphone - 隐藏 UIToolbar UIBarButtonItems

objective-c - 如何在 Xcode 中定义预处理器符号