Uitableview 如何根据用户界面用不同的NSArray加载相同的tableview?
在我的应用程序中,我有一个滚动视图和一个表格视图作为子视图添加,在这个滚动视图中,我有多个菜单按钮(UI按钮)作为子视图添加到我的滚动视图中。我想根据点击的菜单按钮,加载具有不同数组的表格视图。有什么想法吗Uitableview 如何根据用户界面用不同的NSArray加载相同的tableview?,uitableview,ios5,uibutton,tableview,subview,Uitableview,Ios5,Uibutton,Tableview,Subview,在我的应用程序中,我有一个滚动视图和一个表格视图作为子视图添加,在这个滚动视图中,我有多个菜单按钮(UI按钮)作为子视图添加到我的滚动视图中。我想根据点击的菜单按钮,加载具有不同数组的表格视图。有什么想法吗 - (void)viewDidLoad { [super viewDidLoad]; [self PutButtoninScrollView:7]; } -(void)PutButtoninScrollView:(int)numberOfbuttons { myBu
- (void)viewDidLoad
{
[super viewDidLoad];
[self PutButtoninScrollView:7];
}
-(void)PutButtoninScrollView:(int)numberOfbuttons
{
myButton1=[[UIButton alloc]init];
myButton1= [UIButton buttonWithType:UIButtonTypeCustom];
myButton1.frame=CGRectMake(5, 5, 70, 30);
[myButton1 setTitle:@"दुनिया" forState:UIControlStateNormal];
[myButton1 setTag:1];
myButton1.backgroundColor=[UIColor blackColor];
[myButton1 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];
[self.myScrollView addSubview:myButton1];
myButton2=[[UIButton alloc]init];
myButton2= [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton2.frame=CGRectMake(80, 5, 70, 30);
[myButton2 setTitle:@"India" forState:UIControlStateNormal];
[myButton2 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];
[self.myScrollView addSubview:myButton2];
[self.myScrollView setContentSize:CGSizeMake(160, 35)];
_myScrollView.backgroundColor=[UIColor redColor];
[self.view addSubview:self.myScrollView];
}
-(void)ListViewAction:(id)sender
{
NSLog(@"sucessful");
if ([myButton.currentTitle isEqualToString:@"दुनिया"])
{
NSLog(@"successful again 1");
}
else if ([myButton.currentTitle isEqualToString:@"भारत"])
{
NSLog(@"successful again 2");
}
}
问题是当我执行代码时
显示“成功”。这意味着调用了ListViewAction方法,但从未执行我的if语句。试试这个
-(void)PutButtoninScrollView:(int)numberOfbuttons
{
xPosition=5;
for(int i=0;i<numberOfbuttons;i++)
{
myButton= [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame=CGRectMake(xPosition, 5, 70, 30);
myButton.backgroundColor=[UIColor redColor];
[myButton setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
[myButton setTag:i];
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.myScrollView addSubview:myButton];
xPosition+=75;
}
[self.myScrollView setContentSize:CGSizeMake(xPosition,35)];
_myScrollView.backgroundColor=[UIColor redColor];
[self.view addSubview:self.myScrollView];
}
- (void) buttonClicked:(id) sender
{
NSString *strTitle = [sender currentTitle];
// arrItem have list of array items
NextView *detailViewController = [[NextView alloc] initWithNibName:@"NextView" bundle:nil];
detailViewController.arrTableView =[arrItem objectAtIndex:[strTitle integerValue]];
[self.navigationController pushViewController:detailViewController animated:YES];
}
-(无效)PutButtonScrollView:(int)numberOfbuttons
{
xPosition=5;
对于(inti=0;i试试这个
[myButton1 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];
[myButton2 addTarget:self action:@selector(ListViewAction:) forControlEvents:UIControlEventTouchUpInside];
-(无效)ListViewAction:(id)发件人
{
NSLog(@“成功”)
}我们可以借助标记或id指针来实现…很抱歉,我的代码中出现了(ListViewAction:)。我的ListViewAction工作正常。我得到了输出字符串“successful”。我想要的是执行“successful again1”和“successful again2”,最终找到了解决方案:-(void)ListViewAction:(id)发送方{if([[sender currentTitle]isEqualToString:@]दुनिया"]) {NSLog(@“再次成功”);}else如果([[sender currentTitle]IsequalString:@”भारत“]{NSLog(@“successful again1”);}}可能是uibutton作为子视图添加的问题。我读过有关UIGestureRecograiser的文章。但不知道如何使用它。最后它是这样工作的。只需将sender而不是我的按钮放在ListViewAction thanx中,以获得您的帮助@Ravindhiran
if ([[sender currentTitle] isEqualToString:@"दुनिया"])
{
NSLog(@"successful again 1");
}
else if ([[sender currentTitle] isEqualToString:@"भारत"])
{
NSLog(@"successful again 2");
}