Ios UITableView上的图像不工作
在成功地使文本在我的Ios UITableView上的图像不工作,ios,objective-c,uitableview,Ios,Objective C,Uitableview,在成功地使文本在我的UITableView上工作后,我仍然没有使图像工作。似乎UITableViewCells上的LogoURL数组为空,如箭头所示,这是我的代码 #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) MSTable *table; @property (nonatomic, strong) NSMutableArray *items; @property
UITableView
上工作后,我仍然没有使图像工作。似乎UITableViewCells上的LogoURL
数组为空,如箭头所示,这是我的代码
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) MSTable *table;
@property (nonatomic, strong) NSMutableArray *items;
@property (weak, nonatomic) IBOutlet UITableView *MainTableView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// create the activity indicator in the main queue
self.MainTableView.hidden = YES;
UIActivityIndicatorView *ac = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:ac];
[ac startAnimating];
self.client = [MSClient clientWithApplicationURLString:@"https://outnight-mobile.azure-mobile.net/" applicationKey:@"okYeRGfBagYrsbkaqWIRObeDtktjkF10"];
self.table = [self.client tableWithName:@"notifications"];
self.rowitems = [[NSMutableArray alloc] init];
MSQuery *query = [self.table query];
query.fetchLimit = 3;
[query readWithCompletion:^(NSArray *items, NSInteger totalCount, NSError *error)
{
self.rowitems = [items mutableCopy];
[self.MainTableView reloadData];
self.MainTableView.hidden = YES;
int a;
for (a = 0; a < 3; a++)
{
NSDictionary *apt = [self.rowitems objectAtIndex:a];
NSLog(@"%@", apt[@"barID"]);
NSDictionary *barIDDictionary = @{ @"myParam": apt[@"barID"]};
self.client = [MSClient clientWithApplicationURLString:@"https://outnight-mobile.azure-mobile.net/" applicationKey:@"okYeRGfBagYrsbkaqWIRObeDtktjkF10"];
[self.client invokeAPI:@"photos" body:barIDDictionary HTTPMethod:@"POST" parameters:nil headers:nil completion:^(id result, NSHTTPURLResponse *response, NSError *error) {
if (error) {
NSLog(@"Error %@", error );
}
else {
NSString *string = [NSString stringWithFormat:@"%@", [result objectForKey:@"rows"]];
NSString *stringWithoutbracketsend = [string stringByReplacingOccurrencesOfString:@")" withString:@""];
NSString *stringWithoutbracketsfront = [stringWithoutbracketsend stringByReplacingOccurrencesOfString:@"(" withString:@""];
NSString *completion = [stringWithoutbracketsfront stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *newStr = [completion substringFromIndex:1];
NSString *finalstring = [newStr substringToIndex:newStr.length-(newStr.length>0)];
[self.logoURL addObject:finalstring];
NSLog(@"%@",finalstring);
[self.MainTableView reloadData];
self.MainTableView.hidden = NO;
}
}];
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.rowitems count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSDictionary *stress = [self.rowitems objectAtIndex:indexPath.row];
cell.textLabel.text = stress[@"content"];
switch (indexPath.row) {
case 0:
[cell.imageView setImageWithURL:[NSURL URLWithString:[self.logoURL objectAtIndex:(1)]] placeholderImage:[UIImage imageNamed:@"greybox40.png"]];
NSLog(@"%@", [self.logoURL objectAtIndex:(1)]);
break;
case 1:
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"greybox40.png"]];
break;
case 2:
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"greybox40.png"]];
break;
}
return cell;
}
@end
#导入“ViewController.h”
@界面视图控制器()
@属性(非原子,强)MSTable*table;
@属性(非原子,强)NSMutableArray*项;
@属性(弱、非原子)IBUITableView*MainTableView;
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
//在主队列中创建活动指示器
self.MainTableView.hidden=是;
UIActivityIndicatorView*ac=[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:ac];
[ac startAnimating];
self.client=[MSClient clientWithApplicationURLString:@”https://outnight-mobile.azure-mobile.net/“应用程序密钥:@“okYeRGfBagYrsbkaqWIRObeDtktjkF10”];
self.table=[self.client tableWithName:@“notifications”];
self.rowitems=[[NSMutableArray alloc]init];
MSQuery*query=[self.table query];
query.fetchLimit=3;
[查询readWithCompletion:^(NSArray*项、NSInteger totalCount、NSError*错误)
{
self.rowitems=[items mutableCopy];
[self.MainTableView reloadData];
self.MainTableView.hidden=是;
INTA;
对于(a=0;a<3;a++)
{
NSDictionary*apt=[self.rowitems objectAtIndex:a];
NSLog(@“%@”,apt[@“barID”);
NSDictionary*barIDDictionary=@{“myParam”:apt[@“barID”]};
self.client=[MSClient clientWithApplicationURLString:@”https://outnight-mobile.azure-mobile.net/“应用程序密钥:@“okYeRGfBagYrsbkaqWIRObeDtktjkF10”];
[self.client invokeAPI:@“photos”body:barAddictionary HTTPMethod:@“POST”参数:nil headers:nil completion:^(id结果,NSHTTPURLResponse*响应,NSError*错误){
如果(错误){
NSLog(@“错误%@”,错误);
}
否则{
NSString*string=[NSString stringWithFormat:@“%@,[result objectForKey:@“rows”];
NSString*stringWithoutbracketsend=[string STRINGBYREPLACINGOCURNCESOFSTRING:@”)“withString:@]”;
NSString*StringWithoutBrackets前端=[StringWithoutBrackets发送StringByReplacingOfString:@”(“带字符串:@]”);
NSString*completion=[StringWithout方括号前面的stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString*newStr=[completion substringFromIndex:1];
NSString*finalstring=[newStr substringToIndex:newStr.length-(newStr.length>0)];
[self.logoURL addObject:finalstring];
NSLog(@“%@”,最终结果);
[self.MainTableView reloadData];
self.MainTableView.hidden=否;
}
}];
}
}];
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[self.rowitems计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell*单元=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:@“单元”];
NSDictionary*stress=[self.rowitems objectAtIndex:indexath.row];
cell.textlab.text=应力[@“内容”];
开关(indexPath.row){
案例0:
[cell.imageView setImageWithURL:[NSURL URLWithString:[self.logoURL objectAtIndex:(1)]]占位符图像:[UIImage imageNamed:@“greybox40.png”];
NSLog(@“%@,[self.logoURL objectAtIndex:(1)];
打破
案例1:
[cell.imageView setImageWithURL:[NSURL URLWithString:@]http://www.domain.com/path/to/image.jpg“]占位符图像:[UIImage ImageName:@“greybox40.png”];
打破
案例2:
[cell.imageView setImageWithURL:[NSURL URLWithString:@]http://www.domain.com/path/to/image.jpg“]占位符图像:[UIImage ImageName:@“greybox40.png”];
打破
}
返回单元;
}
@结束
正如您在第一个case语句中所看到的,我已经尝试查看是否可以看到数组内容,但我看不到。任何帮助都是虚构的-我确信这与我将重新加载表放在何处有关,但我仍然不确定。您在何处初始化self.logoURL
?并且它在.h文件中的类型应为Strong,与数组的位置相同e textit很强,非原子ICU在向其添加内容之前应首先创建可变数组。self.logoArray=[NSMutableArray];Oterwise请尝试AsyncImageview。,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSDictionary *stress = [self.rowitems objectAtIndex:indexPath.row];
cell.textLabel.text = stress[@"content"];
switch (indexPath.row) {
case 0:
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@"]]]];
NSLog(@"%@", [self.logoURL objectAtIndex:(1)]);
break;
case 1:
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@"]]]];
break;
case 2:
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@"]]]];
break;
}
return cell;
}