Objective c 从其他视图访问表视图的按钮
如何从任何其他视图访问视图中存在的按钮。让我详细说明我有两个视图控制器a和B。在视图a中,我在表视图中有一个按钮,即button1。我想从其他视图访问表视图中的按钮。请帮助。我尝试创建类a的对象,然后写入[objA.tableview按钮1然后我设置了图像]但它没有工作。请帮助。任何帮助都将不胜感激 谢谢,Objective c 从其他视图访问表视图的按钮,objective-c,xcode,ipad,uitableview,object,Objective C,Xcode,Ipad,Uitableview,Object,如何从任何其他视图访问视图中存在的按钮。让我详细说明我有两个视图控制器a和B。在视图a中,我在表视图中有一个按钮,即button1。我想从其他视图访问表视图中的按钮。请帮助。我尝试创建类a的对象,然后写入[objA.tableview按钮1然后我设置了图像]但它没有工作。请帮助。任何帮助都将不胜感激 谢谢, Christy你可以试试这个,给你的按钮添加一个标签,确保它是唯一的 假设您的按钮有标签45;并且您已经在表视图中创建了它 现在,在另一种方法中,您希望像这样使用该按钮:- -(void)d
Christy你可以试试这个,给你的按钮添加一个标签,确保它是唯一的 假设您的按钮有标签45;并且您已经在表视图中创建了它 现在,在另一种方法中,您希望像这样使用该按钮:-
-(void)deletePostMethod
{
UIButton *button=(UIButton *)[self.view viewWithTag:49];
[button setBackgroundColor:[UIColor redColor]];
NSLog(@"button=%@",button);
}
编辑答案:-
- (UITableViewCell *)tableView:(UITableView *)tablefirst cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// I have added a button in my table view in first row
if (indexPath.row==0) {
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 40, 30)];
[btn addTarget:self action:@selector(deletePostMethod) forControlEvents:UIControlEventTouchUpInside];
btn.tag=579;
[cell.contentView addSubview:btn];
}
return cell;
}
在该按钮上单击方法
-(void)deletePostMethod
{
UIButton *button=(UIButton *)[self.view viewWithTag:579];
[button setBackgroundColor:[UIColor redColor]];
NSLog(@"button=%@",button);
}
单击此按钮后,按钮背景色设置为红色。使用ViewController属性访问导航堆栈中所有UIViewController的列表
@property(nonatomic, copy) NSArray *viewControllers
NSArray* allController = self.navigationController.viewControllers ;
for(UIViewController* myAController in allController)
{
if( [myAController isMemberOfClass])
{
//Here Now you have the A controller
MyViewAController* myATempController = (MyViewAController*)myAController;
//Now you could access the property of your A Controller.
}
}
我会使您的按钮成为视图控制器的属性,这样您就可以通过名称访问它 在界面文件中:
@interface MyViewController : UIViewController {
UIButton* myButton;
}
@property (nonatomic, retain) UIButton* myButton;
@end
在您的实现文件中:
@implementation MyViewController
@synthesize myButton;
@end
然后,您可以使用aViewController.myButton获取您的按钮。@christina我希望它能帮助您我无法理解请详细说明,我在一个视图中有一个表视图,在另一个视图中有一个表视图如何从另一个视图访问表视图中的uibutton预设您只需创建一个带有唯一标记的按钮即可where ever让我们假设您已经在1表视图中创建了。现在,无论您想在何处访问该按钮,请使用此行UIButton*button=UIButton*[self.view view with tag:49];它将引用您的按钮。现在您可以在按钮中执行任何您想执行的操作,例如图像更改或其他操作。我是否必须编写self.view或myclassname.view,或者更确切地说是表视图,因为该按钮位于表视图中