Coverflow无法使用webservices数据

时间:2013-04-24 06:52:25

标签: iphone ios

在我的应用程序中我想显示封面流程,我从网上获取代码,它在使用默认数组时工作正常,但在使用json Webservices时它不会连续显示图像,它只显示一个图像,我想要所有的要连续显示的图像。这是示例代码,

- (void)viewDidLoad
{

    NSString *Categor=@"http://hrmsiphone.atrity.info:7006/HRMSService.svc/
    GetEmployeeDesignationByLocation/Date=%@,AP=%@,Unit=%@,Location=%@";

Date = @"2013-04-24";

AP = @"A";
Unit = @"A-UNIT-FULLSHOES";
Location = @"Unit";
NewDic2 = [Array objectAtIndex:0];

 NSString *Category = [NSString stringWithFormat:Categor,Date,AP,Unit,Location];

dispatch_sync(kBgQueue, ^{
    NSData* data = [NSData dataWithContentsOfURL:  kLatestURL];
    [self performSelectorOnMainThread:@selector(fetchedData:)
                           withObject:data
                        waitUntilDone:YES];
});

 - (void)fetchedData:(NSData *)responseData
   {

NSError* error;
NSDictionary* json = [NSJSONSerialization
                      JSONObjectWithData:responseData


                      options:kNilOptions
                      error:&error];
NSArray* Increment  = [ json  objectForKey:@"GetEmployeeDesignationByLocationResult"];



self.Details2 = Increment;

NSLog(@"Index: %@",Increment);

}
 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
return [Details2 count];


}


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

AttenEmpPhto *cell = (AttenEmpPhto *)[tableView    
dequeueReusableCellWithIdentifier:simpleTableIdentifier];      
if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AttenEmpPhto" owner:self     

    cell = [nib objectAtIndex:0];

}

self.NewDic1=[self.Details2 objectAtIndex:indexPath.row];


cell.Name.text = [NSString stringWithFormat:@"%@",  [self.NewDic1 objectForKey:    
 @"Employee_Name"]];            

UIImageView *imageView = [[UIImageView alloc] initWithFrame:cell.frame];
UIImage *image = [UIImage imageNamed:@"003923_full.jpg"];
imageView.image = image;
cell.backgroundView = imageView;

NSString    *imageURL=@"http://hrmsiphone.atrity.info:7006/HRMSService.svc/
GetEmpImage/EmployeeNo=%@";
NSLog(@"Image: %@", imageURL);

NSString *empImage = [NSString stringWithFormat:imageURL,[self.NewDic1 objectForKey:  
@"Employee_No"]];



NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:empImage]];




  covers = [NSMutableArray arrayWithObjects:[UIImage imageWithData:imageData],nil];

NSLog(@"Image: %@", covers);

 NSLog(@"Image: %@", imageData);






coverflow = [[TKCoverflowView alloc] initWithFrame:CGRectMake(0, 50, 500, 300)];
coverflow.coverflowDelegate = self;
coverflow.DataSource = self;
[self.view addSubview:coverflow];
[coverflow setNumberOfCovers:10];



return cell;
}
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)
  interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

        #pragma Coverflow delegate methods
  - (void) coverflowView:(TKCoverflowView*)coverflowView coverAtIndexWasBroughtToFront:
     (int)index{
NSLog(@"Front %d",index);
        }

- (TKCoverflowCoverView*) coverflowView:(TKCoverflowView*)coverflowView coverAtIndex:
   (int)index
 {

TKCoverflowCoverView *cover = [coverflowView dequeueReusableCoverView];

if(cover == nil){
    // Change the covers size here
    cover = [[TKCoverflowCoverView alloc] initWithFrame:CGRectMake(0, 0, 224, 
            300)];     
    cover.baseline = 224;

}



cover.image = [covers objectAtIndex:index % [covers count]];

这里[cover count]返回1,但我需要2(EmployeeNo - 1& 3)

 NSLog(@"CC: %lu", (unsigned long)[covers count] );
 NSLog(@"CM: %@", cover.image );

return cover;

}
   - (void) coverflowView:(TKCoverflowView*)coverflowView coverAtIndexWasDoubleTapped:
(int)index{

TKCoverflowCoverView *cover = [coverflowView coverAtIndex:index];
if(cover == nil) return;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:cover 
    cache:YES];
[UIView commitAnimations];

//  NSLog(@"Index: %d",index);
}

 - (void)didReceiveMemoryWarning
     {
[super didReceiveMemoryWarning];

   }

先谢谢。

2 个答案:

答案 0 :(得分:0)

删除该行

covers = [NSMutableArray arrayWithObjects:[UIImage imageWithData:imageData],nil];

并添加行

if (covers == nil) {
   covers = [[NSMutableArray alloc] init];
}
[covers addObject:[UIImage imageWithData:imageData]];

答案 1 :(得分:0)

- (UIImage *)defaultImage {
    return [UIImage imageNamed:@"default.jpg"];
}

使用此设置来设置默认图像。