2014-02-14 61 views
0

在我的UITableView上成功獲取文本後,仍然無法正常工作。看來LogoURL數組在UITableViewCellsForRow上是空白的,這裏是我的代碼。UITableView上的圖像不工作

#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 

正如您在第一個case語句中所看到的,我試圖查看是否可以看到數組內容,但我不能。任何幫助都會是晶圓廠 - 我確信它與我放置重新加載表的位置有關,但我仍然不確定。

+0

在哪裏初始化'self.logoURL'? – Akhilrajtr

+0

它應該是類型強 – santhu

+0

在.h文件中與文本數組相同的位置 – user3307144

回答

0
-(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; 
} 
+0

Oterwise嘗試AsyncImageview。, –