- 浏览: 340344 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
leslie89757:
[img][img][img][img][img][img][ ...
CocoaPods 安装使用 -
hanmeizhi:
very useful to me. Thanks
Dismissing MPMoviePlayerViewController the right way -
luzj:
这个考虑不周全, 在iOS5的键盘高度就不是这个值了,这样写死 ...
UITextView: move view when keyboard appears -
xjg19870111:
不错。
objective-c NSString 常用操作 -
juedui0769:
现在已经不行了!
android源码下载
In this application we’ll see how to implement a custom accessory view for your UITableView in the form of a checkmark button.
Step 1: Create a Window base application using template. Give the name of the application “CheckMark”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: We need to add the resource file called as “checked.png” and “unchecked.png” into the resource folder. Select resources and add files existing sources and select the checked.png and unchecked.png.
Step 4: Now we’ll add Table view controller class to the project. Choose New file -> Select cocoa touch classes group and then select UITableViewController subclass. Give the name TableView.
Step 5: In the AppDelegate.h file, we define UINavigationController. Make the following changes in the AppDelegate.h file .
Step 6: In the AppDelegate.m file , make the following changes :
Step 7: We added dataArray in the TableView.h file, so make the following changes:
Step 8: Double click the MainWindow.xib file and open it to the Interface Builder. Drag Navigation Controller from the library and place it in the MainWindow. Double click Navigation Controller icon and open the Navigation Controller window. Change the title into “Add CheckMark”. Select View Controller and bring up identity inspector change the class name into TableView. Now drag table view from the library and place it to the Navigation Controller window. Select it and bring up connection inspector, you will see two connection are available dataSource and delegate. Drag dataSource to the table view . Do it once more time for the delegate. Save it and go back to the Xcode.
Step 9: In the TableView.m file make the following changes:
Step 10: Compile and run the application in the Simulator.
Step 1: Create a Window base application using template. Give the name of the application “CheckMark”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: We need to add the resource file called as “checked.png” and “unchecked.png” into the resource folder. Select resources and add files existing sources and select the checked.png and unchecked.png.
Step 4: Now we’ll add Table view controller class to the project. Choose New file -> Select cocoa touch classes group and then select UITableViewController subclass. Give the name TableView.
Step 5: In the AppDelegate.h file, we define UINavigationController. Make the following changes in the AppDelegate.h file .
@interface CheckMarkAppDelegate : NSObject { UIWindow *window; UINavigationController *myNavController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *myNavController;
Step 6: In the AppDelegate.m file , make the following changes :
- (void)applicationDidFinishLaunching:(UIApplication *)application { [window addSubview: myNavController.view]; [window makeKeyAndVisible]; }
Step 7: We added dataArray in the TableView.h file, so make the following changes:
@interface TableView : UITableViewController { @private NSMutableArray *dataArray; }
Step 8: Double click the MainWindow.xib file and open it to the Interface Builder. Drag Navigation Controller from the library and place it in the MainWindow. Double click Navigation Controller icon and open the Navigation Controller window. Change the title into “Add CheckMark”. Select View Controller and bring up identity inspector change the class name into TableView. Now drag table view from the library and place it to the Navigation Controller window. Select it and bring up connection inspector, you will see two connection are available dataSource and delegate. Drag dataSource to the table view . Do it once more time for the delegate. Save it and go back to the Xcode.
Step 9: In the TableView.m file make the following changes:
- (void)viewDidLoad { NSString *path = [[NSBundle mainBundle] pathForResource:@"CheckMark" ofType:@"plist"]; self.dataArray = [NSMutableArray arrayWithContentsOfFile:path]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [dataArray count]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath]; [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *kCustomCellID = @"MyCellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCellID]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.selectionStyle = UITableViewCellSelectionStyleBlue; } NSMutableDictionary *item = [dataArray bjectAtIndex:indexPath.row]; cell.textLabel.text = [item objectForKey:@"text"]; [item setObject:cell forKey:@"cell"]; BOOL checked = [[item objectForKey:@"checked"] boolValue]; UIImage *image = (checked) ? [UIImage imageNamed:@"checked.png"] : [UIImage imageNamed:@"unchecked.png"]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height); button.frame = frame; [button setBackgroundImage:image forState:UIControlStateNormal]; [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; button.backgroundColor = [UIColor clearColor]; cell.accessoryView = button; return cell; } - (void)checkButtonTapped:(id)sender event:(id)event { NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition]; if (indexPath != nil) { [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath]; } } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row]; BOOL checked = [[item objectForKey:@"checked"] boolValue]; [item setObject:[NSNumber numberWithBool:!checked] forKey:@"checked"]; UITableViewCell *cell = [item objectForKey:@"cell"]; UIButton *button = (UIButton *)cell.accessoryView; UIImage *newImage = (checked) ? [UIImage imageNamed:@"unchecked.png"] : [UIImage imageNamed:@"checked.png"]; [button setBackgroundImage:newImage forState:UIControlStateNormal]; }
Step 10: Compile and run the application in the Simulator.
发表评论
-
IOS7.1 企业应用 证书无效 已解决
2014-05-10 10:53 774http://www.cocoachina.com/bbs/r ... -
xCode Find&Replace快捷键
2013-10-28 10:44 907As for Find & Replace, they ... -
iOS整合zxing需要注意的地方
2013-08-02 23:34 2106Well, at last I got it working. ... -
iOS 自定义Tabbar
2013-07-30 22:55 1191http://www.appcoda.com/ios-prog ... -
Apple Push Notification Service总结
2013-07-29 22:39 1115苹果推送通知服务使用总结 1. 在 Mac 上从 KeyCha ... -
iOS 消息推送原理及实现
2013-07-12 13:40 856链接: http://www.dapps.net/dev/ ... -
GIMP IMAGE MAP
2013-05-29 16:13 854使用GIMP 制作 IMAGE MAP 1. 选择图片,用G ... -
INSPIRATION
2013-05-27 18:21 813http://www.patternsofdesign.co. ... -
iOS 自定义控件系列
2013-05-27 17:09 1481iOS自定义控件 自定义UITableViewCell ht ... -
CocoaPods 使用教程
2013-05-27 14:49 768http://mobile.tutsplus.com/tuto ... -
IOS 开发之设置UIButton的title
2013-05-11 22:03 1207btn.frame = CGRectMake(x, y, wi ... -
REActivityViewController 使用 备忘
2013-04-22 21:38 1059REActivityViewController Out o ... -
VPS配置二级域名
2013-04-18 23:08 7881. 域名解析商配置泛解析 主机记录 * 记录类型 A 2. ... -
ios 开发NewsStand指南
2013-04-13 21:44 1324http://www.viggiosoft.com/blog/ ... -
Python Django mod_wsgi Windows 部署过程 备忘
2013-04-10 18:28 1587部署环境:Windows2003Server 1. 安装Ap ... -
网站迁移 备忘
2013-04-10 14:58 7511. 备份数据库。。。导出的格式和编码要注意 2. 完全导出网 ... -
Windows下命令行查看端口占用
2013-04-09 23:42 723在windows命令行窗口下执行: C:\>netst ... -
带预览功能又可分页的UIScrollView
2013-04-05 12:56 823带预览功能又可分页的UIScrollView http:// ... -
25 iOS App 性能优化
2013-04-05 10:51 695http://www.raywenderlich.com/ ... -
UIScrollView滚动, 中间显示整图, 前后露出部分图
2013-04-04 00:12 1200UIScrollView *scrollowView = [[ ...
相关推荐
Start Developing iOS Apps (Swift): Implement a Custom Control.webarchive
Implement a simple fully connected neural network in C language and test it on the mnist dataset. / 使用C语言实现一个简单的全连接神经网络,并在mnist数据集上测试。
Custom shaped layout for Android 自定义形状布局 Features Clip layout and its childview. 2 way to set shape. Also custom shape by implement ShapeModel. Dependency Add this in your build.gradle file ...
1.6.1 Packet Tracer - Implement a Small Network Cisco Packet Tracer 思科模拟器 正确答案文件 可直接上交正确答案文件 本答案版权归mewhaku所有,严禁再次转载!!! Copyright @mewhaku 2022 All Rights ...
Implement a database with Core Data, and design your schema in Xcode Learn to use the iPhone’s signature multi-touch capabilities in your applications Work with the Apple Push Notification Service ...
This book will help you construct a great UI for your apps by teaching you how to create custom Android views. You will start by creating your first Android custom view and go through the design ...
Implement a database with Core Data, and design your schema in Xcode Learn to use the iPhone’s signature multi-touch capabilities in your applications Work with the Apple Push Notification Service ...
标题中的"A C++ wrapper for TWAIN"指的是一个C++编程库,它的主要目的是方便开发者在C++应用程序中集成TWAIN接口。TWAIN(Technology Without An Interesting Name,无趣技术的缩写)是一种标准的图像数据传输协议...
To view the sample's output in Xcode, open the Console by choosing "Console" from the "Run" menu (or entering Command-Shift-R). See the comments for -countByEnumeratingWithState:objects:count: for ...
this book shows you how to integrate these various elements with key design concepts and principles in order to develop a highly usable interface for the touch screen. You'll learn to use existing ...
Objective-C is a powerful and versatile programming language that serves as the foundation for developing applications for Apple platforms, including iPhone, iPad, and Mac. This language combines the ...
Design and Implement Servlets JSPs and EJBs for IBM WebSphere Application Server
It implement some function to pop up a custom view to display the general information for the iphone. It is good project to study the function of pop up view in iphone and ipad development.
implement the objects, operations, and algorithm in a program; and test, correct, and revise the program. He also revisits topics in greater detail as the text progresses. By the end of the book, ...
Many applications on iPhone use machine learning: Siri to serve voice-based requests, the Photos app for facial recognition, and Facebook to suggest which people that might be in a photo. You'll ...
标题 "Implement with Class and Collection a List Collection with a" 暗示了我们需要讨论如何使用类(Class)和集合(Collection)来实现一个列表集合,并具备添加(add)和移除(remove)数据元素的功能。...
A console applicaton, such as a telnet emulator, needs to implement a console window for the user to type commands. It is not that easy to code everything that a text editor does.
1. Implement a blurring filter using the equation (5.6-11,数字图像处理(第三版))in textbook, and blur the test image ‘book_cover.jpg’ using parameters a=b=0.1 and T=1. (20%) 2. Add Gaussian noise ...
标题中的"Implement deep networks for digit classification Exercise 权值矩阵"指的是使用深度网络进行数字分类的实践练习,重点在于权值矩阵。在这个练习中,我们通常会构建一个多层神经网络,如深度信念网络...
"Objective-C for Absolute Beginners: iPhone and Mac Programming Made Easy" is an excellent resource for those starting out in the world of software development for Apple platforms. The book covers ...