2014-03-05 2 views
0

사람이 나를 UIViewController에서 this- 같은 (아이 패드 iOS7에 대한 개발)을 달성하는 데 도움이 될 수 있습니다 제발 내가 jQuery과 UICollectionView (같은 splitViewController) .I 그냥 내가 UITableViewCell에 누를 때 UICollectionView에서 이미지를 변경하고 싶습니다. (나는 & 사용하고 있습니다 button 이상 tableViewCell 및 수집 색인 NSInteger).UITableView 및 UICollectionView 상호 작용 기능은 무엇입니까?

나는 이것을 달성하는 데 도움이된다. 나는 여러 날 동안 노력하고 있지만 지금까지는 달성 할 수 없다. . :(여기

내가 지금까지 무엇을했는지 코드 내 viewDidLoad에서

: CollectionViewMethods에서 다음

self.collectionViewImages=[[NSMutableArray alloc]initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",nil] ; 

:

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{ 
    return 1; 
} 
-(NSInteger)collectionView:(UICollectionView *)collectionView 
numberOfItemsInSection:(NSInteger)section 
{ 

    return [_collectionViewImages count]; 

} 


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
      cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UICollectionViewCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" 
           forIndexPath:indexPath]; 


    NSString *collectionViewImageName=[self.collectionViewImages objectAtIndex:indexPath.row]; 
    UIImageView * collectionImage = (UIImageView*)[myCell viewWithTag:11]; 

    collectionImage.image =[UIImage imageNamed:collectionViewImageName]; 

return myCell; 
} 

다음에 ButtonClick (ofTableViewCell) - - (각 버튼의 태그를 NSInteger에 수집하고 해당 속성을 numberOfItemsInSection에 사용 중입니다. 이 같은

-(void)btnTapped:(id)sender{ 
int tag= [(UIButton *)sender tag]; 
NSLog(@"Button Pressed%d",tag); 
_buttonIndex=tag; 
//_buttonIndex is NSInteger property 
//If i add object in NSMutableArray and call reloadData my UI hangs here only. 
//If I empty my NSMutableArray and add new objects in it and then call reloadData, I am getting NSRangeException. 
} 

그리고 지금은 numberOfItemsInSection에서이 속성을 사용하고 ...

if (_buttonIndex==1){ 

    [collectionImage setImage:[UIImage imageNamed:[_array1 objectAtIndex:indexPath.row]]]; 
    //My _array1 has 4 objects and my collectionViewImages array has 7 objects. 

    } 

당신이 시도하고 있기 때문에

*** Terminating app due to uncaught exception 'NSRangeException', 
reason: '*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]' 
+0

@Cyrille 질문이 업데이트되었습니다. –

답변

0

그것의 충돌로 내가 오류 메시지가 무엇입니까 배열에서 인덱스 4의 항목을 가져옵니다. 그러나 인덱스 만 있습니다 : 0,1,2,3. (이 여기에 충돌하는 경우)

두 줄에 배열 1의 내용을 확인 : 거기 충돌하는 경우

[collectionImage setImage:[UIImage imageNamed:[_array1 objectAtIndex:indexPath.row]]]; 

그렇지 않으면 당신이 objectAtIndex에 전화 확인 다른 장소를 찾을 수 있습니다.

+0

내가하고있는 어리 석음은 UICollectionView에 대한 'property'를 만들었지 만 Interface Builder와의 연결을 잊어 버렸습니다. :피 –