2012-09-17 101 views
-5
- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 

NSMutableArray *imageArray=[[NSMutableArray alloc]initWithObjects:@"pic1.png",@"pic2.png",@"pic3.png",@"pic4.png",nil]; 


NSMutableArray *username=[[NSMutableArray alloc]initWithObjects:@"A",@"B",@"C",@"D" ,nil]; 

     [self scrollViewAction]; 

    } 




    -(void)scrollViewAction 

    { 

     int x=5,y=0; 

     for(int i=0;i<[DetailsArray count];i++) 

     { 

      UIButton *btn=[[UIButton alloc]init]; 


[btn setFrame:CGRectMake(x, y, 90, 90)]; 

      UILabel *usernameLabel=[[UILabel alloc]init]; 

      [btn addTarget:self action:@selector(btnClicked) 

forControlEvents:UIControlEventTouchUpInside]; 

      btn.tag=i; 

      image=[UIImage imageWithData:[NSData dataWithContentsOfFile:@"imageArray"]]; 

      if(i==0||i==1||i==2) 


      { 


       usernameLabel=[[UILabel alloc]initWithFrame:CGRectMake(x,90,90,10)]; 


      } 

else 

      { 


       usernameLabel=[[UILabel alloc]initWithFrame:CGRectMake(x,y+90,90,10)]; 

      } 



      usernameLabel.text=username; 

    -------------------------------------------------------(here I am getting cant compare 

array with string) 

      usernameLabel.backgroundColor=[UIColor blueColor]; 

      usernameLabel.font=[UIFont systemFontOfSize:12]; 

      [usernameLabel setTextAlignment:UITextAlignmentCenter]; 

      [self.scrollview addSubview:btn]; 

      [self.scrollview addSubview:usernameLabel]; 

      x=x+110; 

      if((i+1)%3==0) 

      { 

       x=5; 


       y=y+110;//y=y+115; 




      } 



      self.scrollview.contentSize= CGSizeMake(320,y+200); 

     } 




    } 
+0

我真的不知道你想在這裏做什麼,數組是你想使用和爲什麼你比較數組爲字符串?你的意思是你想在字符串數組中找到匹配的字符串嗎? –

+0

是的...我想在字符串數組中找到匹配的字符串 – Jaffer

+0

如果您希望人們閱讀它以提供和回答,並且提供關於您想要的內容的一些解釋,而不僅僅是代碼轉儲非常格式化。 – 8vius

回答

3
usernameLabel.text=username; 

用戶名的NSMutableArray的一個實例,這是不是有什麼預期(的NSString的一個實例)。 也許你想要做這樣的事情?

usernameLabel.text=[username objectAtIndex:0]; 
1
for (NSString *name in username) { 
    if ([name isEqualToString(usernameLabel.text)]) 
//matched string found 
} 
相關問題