2013-04-24 60 views
0

在我的應用程序中,我想要顯示coverflow過程,我從在線獲取代碼,使用默認數組時它工作正常,但在使用json Webservices時不連續顯示圖像,它只顯示一個圖像,我要顯示continously.Here的樣本代碼的所有圖像,Coverflow不能與webservices一起使用數據

- (void)viewDidLoad 
{ 

    NSString *[email protected]"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 *[email protected]"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]]; 

這裏[覆蓋計數]返回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]; 

    } 

在此先感謝。

回答

0

刪除線

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

,並添加行

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

嗨Aravind,小懷疑,如果ImageData是NILL,它會出錯,如何設置一個默認圖像,以顯示在Coverflow中,其中imageData是nill。 – 2013-05-04 11:20:05

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

使用這個設置默認圖像。

相關問題