iOS小知识点(二)
来源:互联网 发布:如何开实体淘宝店 编辑:程序博客网 时间:2024/05/01 13:40
活动表单
<UIActi*****heetDelegate>
- (IBActive)someButtonPressed:(id)sender
{
UIActi*****heet*acti*****heet =[[UIActi*****heetalloc]
initWithTitle:@”Are yousure?”
delegate:self
cancelButtonTitle:@”Noway!”
destructiveButtonTitle:@”Yes,I’m Sure!”
otherButtonTitles:nil];
[acti*****heetshowInView:self.view];
[acti*****heetrelease];
}
警告视图
<UIAlertViewDelegate>
- (void) acti*****heet:(UIActi*****heet*)acti*****heetdidDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex !=[acti*****heetcancelButtonIndex])
{
NSString*message = [[NSStringalloc] initWithFormat:@”You can
breathe easy, everything wentOK.”];
UIAlertView *alert =[[UIAlertView alloc]
initWithTitle:@”Something wasdone”
message:message
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles:nil];
[alertshow];
[alertrelease];
[messagerelease];
}
}
动画效果
-(void)doChange:(id)sender
{
if(view2 == nil)
{
[self loadSec];
}
[UIView beginAnimati*****:nil context:NULL];
[UIView setAnimationDuration:1];
[UIViewsetAnimationTransition:([view1superview]?UIViewAnimationTransitionFlipFromLeft:UIViewAnimationTransitionFlipFromRight)forView:self.viewcache:YES];
if([view1 superview]!=nil)
{
[view1 removeFromSuperview];
[self.view addSubview:view2];
}else {
[view2 removeFromSuperview];
[self.view addSubview:view1];
}
[UIView commitAnimati*****];
}
Table View<UITableViewDateSource>
#pragma mark -
#pragma mark Table View Data Source Methods
//指定分区中的行数,默认为1
-(NSInteger)tableView:(UITableView*)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
//设置每一行cell显示的内容
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *SimpleTableIndentifier=@"SimpleTableIndentifier";
UITableViewCell *cell =[tableViewdequeueReusableCellWithIdentifier:SimpleTableIndentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:SimpleTableIndentifier]
autorelease];
}
UIImage*image =[UIImage imageNamed:@"13.gif"];
cell.imageView.image = image;
NSUInteger row = [indexPath row];
cell.textLabel.text = [listDataobjectAtIndex:row];
cell.textLabel.font =[UIFontboldSystemFontOfSize:20];
if(row< 5)
cell.detailTextLabel.text = @"Bestfriends";
else
cell.detailTextLabel.text=@"friends";
return cell;
}
图像、文本标签和详细文本标签
图像:如果设置图像,则它显示在文本的左侧;文本标签:这是单元的主要文本(UITableViewCellStyleDefault 只显示文本标签);详细文本标签:这是单元的辅助文本,通常用作解释性说明或标签
UITableViewCellStyleSubtitle
UITableViewCellStyleDefault
UITableViewCellStyleValue1
UITableViewCellStyleValue2
<UITableViewDelegate>
#pragma mark -
#pragma mark Table View Delegate Methods
//把每一行缩进级别设置为其行号
- (NSInteger)tableView:(UITableView*)tableViewindentationLevelForRowAtIndexPath:(NSIndexPath*)indexPath
{
NSUInteger row = [indexPath row];
return row;
}
//获取传递过来的indexPath值
- (NSIndexPath *)tableView:(UITableView*)tableViewwillSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (row == 0)
return nil;
return indexPath;
}
- (void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSUInteger row = [indexPath row];
NSString *rowValue = [listDataobjectAtIndex:row];
NSString *message = [[NSString alloc]initWithFormat:@"You selected%@",rowValue];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"RowSelected"
message:message
delegate:nil
cancelButtonTitle:@"Yes, Idid!"
otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
[tableViewdeselectRowAtIndexPath:indexPathanimated:YES];
}
//设置行的高度
- (CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
NavigationController 推出push 推出pop
[self.navigationControllerpushViewController:_detailControlleranimated:YES];
[self.navigationControllerpopViewControllerAnimated:YES];
Debug:
NSLog(@"%s %d", __FUNCTION__,__LINE__);
点击textField外的地方回收键盘
先定义一个UIControl类型的对象,在上面可以添加触发事件,令SEL实践为回收键盘的方法,最后将UIControl的实例加到当前View上。
UIControl *m_control = [[UIControlalloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[m_controladdTarget:selfaction:@selector(keyboardReturn)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:m_control];
- (void) keyboardReturn
{
[aTextField resignFirstResponder];
}
键盘覆盖输入框
当键盘调出时将输入框覆盖时,可以用下方法:
-(BOOL)textFieldShouldBeginEditing:(UITextField*)textField
{
[self.view setFrame:CGRectMake(0, -100,320, 480)];
return YES;
}
[self.view setFrame:CGRectMake(0, 0,320,480)]; return YES; }
当准备输入时,将视图的位置上调100,这样键盘就不能覆盖到输入框。
当依赖注入方法不好使时,可以在AppDelegate内申明一个全局的控制器实例_anotherViewController,在另一个需要使用_anotherViewController的地方定义以下委托方法,使用共享的UIApplication实例来获取该委托的引用
SomeAppDelegate *appDelegate =(SomeAppDelegate *)[[UIApplicationsharedApplication] delegate];
_anotherViewController=appDelegate._anotherViewController;
UIViewController内建TableView
纯代码在UIViewController控制器内建Table View
@interface RootViewController :UIViewController<UITableViewDelegate,UITableViewDataSource> {
NSArray *timeZoneNames;
}
@property (nonatomic,retain)NSArray*timeZoneNames;
@end
(void) loadView
{
UITableView *tableView = [[UITableViewalloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]style:UITableViewStylePlain];
tableView.autoresizingMask =(UIViewAutoresizingFlexibleHeight |UIViewAutoresizingWidth);
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
self.view = tableView;
[tableView release];
}
将plist文件中的数据赋给数组
NSString *thePath = [[NSBundle mainBundle]pathForResource:@"States"ofType:@"plist"];
NSArray *array =[NSArrayarrayWithContentsOfFile:thePath];
<UIActi*****heetDelegate>
{
}
警告视图
{
}
动画效果
-(void)doChange:(id)sender
{
if(view2 == nil)
{
[self loadSec];
}
[UIView beginAnimati*****:nil context:NULL];
[UIView setAnimationDuration:1];
[UIViewsetAnimationTransition:([view1superview]?UIViewAnimationTransitio
{
[view1 removeFromSuperview];
[self.view addSubview:view2];
}else {
[view2 removeFromSuperview];
[self.view addSubview:view1];
}
[UIView commitAnimati*****];
}
Table View
#pragma mark -
#pragma mark Table View Data Source Methods
//指定分区中的行数,默认为1
-(NSInteger)tableView:(UITableView*)tableView
{
return [self.listData count];
}
//设置每一行cell显示的内容
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *SimpleTableIndentifier=@"SimpleTableIndentifier";
UITableViewCell *cell =[tableViewdequeueReusable
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubt
reuseIdentifier:SimpleTableIndentifier]
autorelease];
}
cell.imageView.image = image;
NSUInteger row = [indexPath row];
cell.textLabel.text = [listDataobjectAtIndex:row];
cell.detailTextLabel.text = @"Bestfriends";
else
return cell;
}
图像、文本标签和详细文本标签
图像:如果设置图像,则它显示在文本的左侧;文本标签:这是单元的主要文本(UITableViewCellStyleDefa
UITableViewCellStyleSubt
UITableViewCellStyleDefa
UITableViewCellStyleValu
UITableViewCellStyleValu
<UITableViewDelegate>
#pragma mark -
#pragma mark Table View Delegate Methods
//把每一行缩进级别设置为其行号
- (NSInteger)tableView:(UITableView*)tableViewindentationLevelForRowAt
{
NSUInteger row = [indexPath row];
return row;
}
//获取传递过来的indexPath值
- (NSIndexPath *)tableView:(UITableView*)tableViewwillSelectRowAtIndexPath
{
NSUInteger row = [indexPath row];
if (row == 0)
return nil;
return indexPath;
}
- (void)tableView:(UITableView*)tableViewdidSelectRowAtI
{
NSUInteger row = [indexPath row];
NSString *rowValue = [listDataobjectAtIndex:row];
NSString *message = [[NSString alloc]initWithFormat:@"You selected%@",rowValue];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"RowSelected"
message:message
[alert show];
[alert release];
[message release];
[tableViewdeselectRowAtIndexPath:indexPathanimated:YES];
}
//设置行的高度
- (CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
NavigationController 推出push 推出pop
[self.navigationControllerpush
[self.navigationControllerpopV
Debug:
NSLog(@"%s %d", __FUNCTION__,__LINE__);
点击textField外的地方回收键盘
先定义一个UIControl类型的对象,在上面可以添加触发事件,令SEL实践为回收键盘的方法,最后将UIControl的实例加到当前View上。
UIControl *m_control = [[UIControlalloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[m_controladdTarget:selfaction:@selector(keyboardReturn)
forControlEvents:UIControlEventTouchUpIns
[self.view addSubview:m_control];
- (void) keyboardReturn
{
[aTextField resignFirstResponder];
}
键盘覆盖输入框
当键盘调出时将输入框覆盖时,可以用下方法:
-(BOOL)textFieldShouldBeginEdit
{
[self.view setFrame:CGRectMake(0, -100,320, 480)];
return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
当准备输入时,将视图的位置上调100,这样键盘就不能覆盖到输入框。
当依赖注入方法不好使时,可以在AppDelegate内申明一个全局的控制器实例_anotherViewController,在另一个需要使用_anotherViewController的地方定义以下委托方法,使用共享的UIApplication实例来获取该委托的引用
SomeAppDelegate *appDelegate =(SomeAppDelegate *)[[UIApplicationsharedApplication] delegate];
_anotherViewController=appDelegate._anotherViewController;
UIViewController内建TableView
纯代码在UIViewController控制器内建Table View
@interface RootViewController :UIViewController<UITableViewDelegate,UITableViewDataSource> {
NSArray *timeZoneNames;
}
@property (nonatomic,retain)NSArray*timeZoneNames;
@end
(void) loadView
{
UITableView *tableView = [[UITableViewalloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]style:UITableViewStylePlain];
tableView.autoresizingMask =(UIViewAutoresizingFlexib
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
self.view = tableView;
[tableView release];
}
将plist文件中的数据赋给数组
NSString *thePath = [[NSBundle mainBundle]pathForResource:@"States"ofType:@"plist"];
NSArray *array =[NSArrayarrayWithContents
- iOS小知识点(二)
- iOS小知识点总结(二)
- UITableView小知识点(二)
- IOS小知识点
- iOS小知识点(一)
- iOS小知识点(三)
- iOS小知识点总结
- ios 小知识点汇总
- ios 小知识点
- iOS --小知识点
- iOS架构小知识点
- iOS之小知识点
- ios小知识点积累
- iOS小知识点
- iOS小知识点
- IOS小知识点总结
- iOS一些小知识点
- iOS 开发小知识点
- UIScrollView详解
- iOS项目常用第三方开源库网址
- jsp+Servlet学习(一)简单实例
- 联网请求
- iOS小知识点(一)
- iOS小知识点(二)
- iOS小知识点(三)
- iOS小知识点(四)网络篇
- UIScrollView 原理详解
- iOS 关键字
- [译]Kinect for Windows SDK开发入门(五):景深数据处理 下
- sourceFlorge上有关Verilog/systemC/SystemVerilog的开源项目
- oracle emca
- AOP入门(二)