我已在UITableViewCell
中以编程方式创建了一个按钮,我希望它在单击时打开一个新的表视图或弹出窗口。请给我一些教程或提示。以下是我的代码:
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(0,0,360,25);
[button addTarget:self action:@selector(dropDownClick) forControlEvents:UIControlEventTouchUpInside];
-(IBAction)dropDownClick
{
//Here I know there should be some code but I am not getting what it should be since I am new to iPad/iPhone development
}
答案 0 :(得分:4)
如果您只想在点按按钮时显示弹出窗口,可以使用UIAlertVIew
- (IBAction)dropDownClick {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title of popup"
message:@"Did this popup show?"
delegate:self
cancelButtonTitle:@"Yes"
otherButtonTitles:nil];
[alert addButtonWithTitle:@"No"];
[alert show];
}
答案 1 :(得分:0)
这里有一个样本
//DISEGNO DELLE CELLE
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier;
CellIdentifier = @"CellStorico";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
CGRect tRect1 = CGRectMake(0.0f, 3.0f, 768.0f, 40.0f);
id title1 = [[UIButton alloc] initWithFrame:tRect3];
[title1 addTarget:self action:@selector(ClickCheck:) forControlEvents:UIControlEventTouchUpInside];
[title1 setTag:3];
[cell addSubview:title1];
[title1 release];
}
if ([[[Storico objectAtIndex:[indexPath row]] objectForKey:@"Selezionato"] isEqualToString:@"0"]) {
[(UIButton *) [cell viewWithTag:3] setImage:[UIImage imageNamed:@"NoCheck.png"] forState:UIControlStateNormal];
[(UIButton *) [cell viewWithTag:3] setImage:[UIImage imageNamed:@"NoCheck.png"] forState:UIControlStateHighlighted];
[(UIButton *) [cell viewWithTag:3] setImage:[UIImage imageNamed:@"NoCheck.png"] forState:UIControlStateSelected];
} else {
[(UIButton *) [cell viewWithTag:3] setImage:[UIImage imageNamed:@"Check.png"] forState:UIControlStateNormal];
[(UIButton *) [cell viewWithTag:3] setImage:[UIImage imageNamed:@"Check.png"] forState:UIControlStateHighlighted];
[(UIButton *) [cell viewWithTag:3] setImage:[UIImage imageNamed:@"Check.png"] forState:UIControlStateSelected];
}
return cell;
}
点击管理
-(void)ClickCheck:(id)sender{
//Ex. Load a New View
FrmScadenzeGenerali *SchermataScadenzeGenerali=[[FrmScadenzeGenerali alloc] initWithNibName:@"FrmScadenzeGenerali" bundle:nil];
[[self navigationController] pushViewController:SchermataScadenzeGenerali animated:YES];
[SchermataScadenzeGenerali release];
//Ex. PopUp a View
[self.view insertSubview:[TabTestata view] atIndex:0];
//Show a Message
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"Attenzione!" message:@"Error Text Message To Show!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[Alert show];
[Alert release];
}
答案 2 :(得分:0)
我假设您在UINavigationController
上使用了UITableView
。
如果是这样,你可以试试这个让它打开一个新的表视图:
UITableViewController
的子类。确保选中名为“With XIB for user interface”的复选框。给它起一个名字,即“MyTableViewController”。dropDownClick
方法所在班级的实施文件(以.m结尾的文件),并使用#import "MyTableViewController.h"
导入新班级。在类的顶部(.m文件)执行此操作。dropDownClick
方法修改为以下行:-(IBAction)dropDownClick
{
MyTableViewController *vc = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController"]; // Loads a .xib file called "MyTableViewController.xib"
[self.navigationController pushViewController:vc animated:YES]; // This is where the swapping happens.
[vc release]; // Remember to do this if your app does not use ARC.
}
您也可以在不使用.xib的情况下执行此操作,但之后会有所不同。