[英]Open PopUp (kind of tableview) on UITabBaritem Click - iPad
[英]programmatically created button click to open a tableview or popup
我已经在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
}
如果您只想在点击按钮时显示弹出窗口,则可以使用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];
}
这是一个样本来做
//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];
}
我假设您将UINavigationController
与UITableView
。
如果是这样,您可以尝试这样做以使其打开新的表格视图:
UITableViewController
的子类。 确保选中名为“使用XIB作为用户界面”的复选框。 给它起一个名字,即“ 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的情况下执行此操作,但这会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.