0

在我的应用程序中,我想显示coverflow过程,我从网上获得了代码,使用默认数组时它工作正常,但是在使用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]];

这里 [covers 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];

   }

提前致谢。

4

2 回答 2

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

使用这个来设置默认图像。

于 2014-05-27T09:59:53.533 回答
0

删除该行

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

并添加行

if (covers == nil) {
   covers = [[NSMutableArray alloc] init];
}
[covers addObject:[UIImage imageWithData:imageData]];
于 2013-04-26T17:44:00.917 回答