Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableview从头开始_Ios_Objective C_Uitableview - Fatal编程技术网

Ios UITableview从头开始

Ios UITableview从头开始,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个UITableView,我需要添加文本和图像-简单。 文本来自数据库中的一个表,图像来自另一个表。这些表通过ID列链接 文本来自一个SQL命令块,它还带来了ID。然后使用自定义API查询ID,并返回图像的URL 在经历了这么多麻烦之后。我写得很简单。开始 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a

我有一个
UITableView
,我需要添加文本和图像-简单。 文本来自数据库中的一个表,图像来自另一个表。这些表通过ID列链接

文本来自一个SQL命令块,它还带来了ID。然后使用自定义API查询ID,并返回图像的URL

在经历了这么多麻烦之后。我写得很简单。开始

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    ImageURL = [[NSMutableArray alloc] initWithObjects:@"http://calcuttans.com/palki/wp-content/uploads/2009/02/kidscover-small.png",@"http://outtonightapp.com/uploads/wether2.jpg",@"http://outtonightapp.com/uploads/wether3.jpg",nil];
    notification = [[NSMutableArray alloc] initWithObjects:@"wow",@"shit",@"tito", nil];  
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

    // putting text in rows by indexpath.row
    cell.textLabel.text = notification[indexPath.row];

    // putting an image on a row

    switch (indexPath.row) {
        case 0:
            [cell.imageView setImageWithURL:[NSURL URLWithString:[ImageURL objectAtIndex:(0)]] placeholderImage:[UIImage imageNamed:@"greybox40.png"]];
            break;
        case 1:
            [cell.imageView setImageWithURL:[NSURL URLWithString:[ImageURL objectAtIndex:(1)]] placeholderImage:[UIImage imageNamed:@"greybox40.png"]];
            break;
        case 2:
            [cell.imageView setImageWithURL:[NSURL URLWithString:[ImageURL objectAtIndex:(2)]] placeholderImage:[UIImage imageNamed:@"greybox40.png"]];
            break;
    }
    return cell;
}

@end
现在我需要删除数组,从SQL中获取数据并放入数组中,但由于程序流的原因,当我在过去这样做时,它们还没有出现。那么,如何最好地将它们放在一个数组中呢。我应该为文本和图像创建一个
.h
.m
文件,然后从
viewDidLoad
运行它们吗。我不想处于这样的位置:我拥有所有的数据,但它又没有显示在tableview中。目前这段代码有效

谢谢


jason

[view didLoad]
中启动应用程序,在加载数据时显示一些活动指示器,
当您在
通知中获取所有数据时,
数组调用
[\u yourTableViewName reloadData]和停止活动指示器

在我看来,您并不是真的想“删除阵列”

tableView本质上是一个ui设备,用于表示数组,或者在分组表的情况下,是一个数组数组。每个单元格应该表示数组中的一个成员,以便屏幕上的内容与数据模型匹配。在您的示例中,我将查看NSDictionary的nsarray,每个NSDictionary都有对象的匹配键,如NSStrings和images等,或者您自己的自定义类的对象数组,这些对象的属性可以在您检索数据时设置,如图像文件名,字符串等。模型应始终与屏幕上绘制的内容相匹配

文本来自一个SQL命令块,它还带来 身份证

因此,形成一个
字典
,ID作为键,文本作为值。返回
numberOfRowsInSection
cellforrowatinexpath
中的字典计数,从ID创建url并查询图像

例如,您的dict可能具有以下结构:

{
   "1" : "wow",
   "2" : "shit"
}
现在将
numberOfRowsInSection
中的字典计数返回为

return [dict count];
现在,在
cellforrowatinexpath
中,获取id

NSString *id= [[actorsDictionary allKeys] objectAtIndex:indexPath.row];
//Create your custom api based on id and call to get image
//Note: You can try out AsyncImageView if you want

这只是满足您需求的另一种方式。希望有帮助。

[cell.imageView setImageWithURL:[NSURL URLWithString:[ImageURL objectAtIndex:indexath.row]]占位符图像:[UIImage imageNamed:@“greybox40.png”]?在访问此视图控制器或在viewDidLoad中查询数据之前,您可能已经准备好数据(数组)。我建议您创建一个包含文本和图像细节的类(比如Data.h&Data.m)。你的数组应该包含这个自定义类的对象,我知道,这样数据就可以加载到不同的线程中,而UI线程一直保持到数据加载为止?任何我可以使用的活动指示器的想法,如果可能的话,还有一些快速代码示例。默认情况下,所有网络请求都是异步的,不要担心这一点。或者更好的是,你可以使用AFN网络来帮助所有的厨房。关于活动指示器,我的意思是
UIActivityIndicatorView
正确,因此我使用UIActivityIndicatorView来阻止UI。从数组中获取所有详细信息,然后使用[重新加载数据]?