- 浏览: 1482541 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (419)
- XMPP (19)
- Android (180)
- Java (59)
- Network (4)
- HTML5 (13)
- Eclipse (9)
- SCM (23)
- C/C++ (4)
- UML (4)
- Libjingle (15)
- Tools&Softwares (29)
- Linphone (5)
- Linux&UNIX (6)
- Windows (18)
- Google (10)
- MISC (3)
- SIP (6)
- SQLite (5)
- Security (4)
- Opensource (29)
- Online (2)
- 文章 (3)
- MemoryLeak (10)
- Decompile (5)
- Ruby (1)
- Image (1)
- Bat (4)
- TTS&ASR (28)
- Multimedia (1)
- iOS (20)
- Asciiflow - ASCII Flow Diagram Tool.htm (1)
- Networking (1)
- DLNA&UPnP (2)
- Chrome (2)
- CI (1)
- SmartHome (0)
- CloudComputing (1)
- NodeJS (3)
- MachineLearning (2)
最新评论
-
bzhao:
点赞123!
Windows的adb shell中使用vi不乱码方法及AdbPutty -
wahahachuang8:
我觉得这种东西自己开发太麻烦了,就别自己捣鼓了,找个第三方,方 ...
HTML5 WebSocket 技术介绍 -
obehavior:
view.setOnTouchListenerview是什么
[转]android 一直在最前面的浮动窗口效果 -
wutenghua:
[转]android 一直在最前面的浮动窗口效果 -
zee3.lin:
Sorry~~
When I build "call ...
Step by Step about How to Build libjingle 0.4
http://www.iphonedevcentral.com/indexed-uitableview-tutorial/
Tackling that handy index on the right side of table views is really not that complicated. In fact, it only requires that you implement two methods. In this tutorial, I’m going to take you step-by-step on how to wire it all together.
Prerequisites
If you were able to follow my previous tutorials , you’re going to be just fine with this one. I assume that you have iPhone SDK 3.x downloaded and installed, know how to create an empty project and files in Xcode and know a thing or two about Objective-C and Cocoa touch. While I am using iPhone SDK 3.2 Beta, I compiled this project against version 3.1.3, which is the current live version.
Let’s get started!
1 .Set up your project
In Xcode, go to File -> New Project and choose Navigation-based Application from the iPhone OS tab. Name the application IndexedTable . At this point, you should have a runnable app with an empty table in it.
2. Create a data source
Instead of hardcoding a bunch of values, country names and whatnot, let’s create a simple method that will generate a bunch of strings from the letters of the alphabet so that our UITableView has something to work with.
Create a new class called DataGenerator . Right-click on the Classes group in the project browser and choose New File . Let the file be an Objective-C class (subclass of NSObject) and name it DataGenerator . This class will only have one static method (for now) that will simply return an array of words from letters. As such, we’ll name it wordsFromLetters .
In DataGenerator.h , insert the following code:
@interface DataGenerator : NSObject { } + (NSArray *) wordsFromLetters; @end
Now, let’s implement this method. Open DataGenerator.m and put this code in it:
@implementation DataGenerator #define WORD_LENGTH 5 static NSString *letters = @"abcdefghijklmnopqrstuvwxyz"; + (NSArray *) wordsFromLetters { NSMutableArray *content = [NSMutableArray new]; for (int i = 0; i < [letters length]; i++ ) { NSMutableDictionary *row = [[[NSMutableDictionary alloc] init] autorelease]; char currentWord[WORD_LENGTH + 1]; NSMutableArray *words = [[[NSMutableArray alloc] init] autorelease]; for (int j = 0; j < WORD_LENGTH; j++ ) { if (j == 0) { currentWord[j] = toupper([letters characterAtIndex:i]); } else { currentWord[j] = [letters characterAtIndex:i]; } currentWord[j+1] = '\0'; [words addObject:[NSString stringWithCString:currentWord encoding:NSASCIIStringEncoding]]; } char currentLetter[2] = { toupper([letters characterAtIndex:i]), '\0'}; [row setValue:[NSString stringWithCString:currentLetter encoding:NSASCIIStringEncoding] forKey:@"headerTitle"]; [row setValue:words forKey:@"rowValues"]; [content addObject:row]; } return content; } @end
I’m not going to spend a whole of time explaining what’s going on here because this tutorial is really about adding an index bar to your UITableView. But let’s briefly talk what’s it all about. This method loops through an array letters one-by-one. For each letter it then generates a bunch of words to fill up our content. The final structure of the NSArray we’re returning is going to look something like this:
NSArray =>
-
NSDictionary
- headerTitle => ‘A’
- rowValues => {”A”, “Aa”, “Aaa”, “Aaaa”}
-
NSDictionary
- headerTitle => ‘B’
- rowValues => {”B”, “Bb”, “Bbb”, “Bbbb”}
- etc.
You’ll see how we’re using this array later on. Also note that this list is implicitly ordered.
3. Fill in UITableView with values from DataGenerator
Next we’re going to populate the currently empty table with data we get from our data generator. Open RootViewController.h and add these two instance variables to the class:
#import "DataGenerator.h" @interface RootViewController : UITableViewController { NSArray *content; NSArray *indices; }
content will hold our array of dictionaries while indices will hold all initial letters for each word in the list. Let's fill those up. Open RootViewController.m implementation file and override the method viewDidLoad with the following:
- (void)viewDidLoad { [super viewDidLoad]; content = [DataGenerator wordsFromLetters]; indices = [[content valueForKey:@"headerTitle"] retain]; }
You can see that we're using [DataGenerator wordsFromLetters] to simply fill in the content variable. The second line of that method returns all keys from the dictionaries in content as an array. So indices now holds all letters of the alphabet.
We next override the two methods that tell our UITableView how many sections it has and how many rows there are in each section.
// Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [content count]; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[[content objectAtIndex:section] objectForKey:@"rowValues"] count] ; }
The number of sections is equal to the number of letters in our list and the number of rows of each section is equal to the count of each array under its corresponding letter.
Finally, we implement cellForRowAtIndexPath so that it displays words from our list in the table. We handle headers for sections in titleForHeaderInSection . This method queries our content at a particular section and demands a headerTitle to be returned as header of that section.
// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [[[content objectAtIndex:indexPath.section] objectForKey:@"rowValues"] objectAtIndex:indexPath.row]; return cell; }
You should be able to run your app now (CMD + R) and see something like this:
4. Add index to the table
There is nothing new in what we've done so far. We simply filled in a UITableView with some data. We're now ready to add our index to it. For that, we'll need to implement two methods: sectionIndexTitlesForTableView and sectionForSectionIndexTitle .
Add this code to RootViewController.m :
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return [content valueForKey:@"headerTitle"]; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { return [indices indexOfObject:title]; }
sectionIndexTitlesForTableView: In order to properly render the index, the UITableView needs to know all index titles to display. This method returns an array of strings containing all indices. In our case, A, B, C, D, etc.
sectionForSectionIndexTitle: When you start scrolling through the index, the table needs to know how far down/up to scroll so that the letter you're touching corresponds the appropriate section in the table. This method returns an index value (integer) of the section you're currently touching in the index.
One more thing we need to do before we run our app is to add titles to each section header in UITableView.
- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { return [[content objectAtIndex:section] objectForKey:@"headerTitle"]; }
5. Run your app
If everything went well, you should now be able to run your app and see the final product. You'll see the index on the right and scrolling over it will scroll the table appropriately.
Conclusion
Voilà! That wasn't that hard was it? The main get-away from this tutorial are the two methods you need to implement in order for the index to show up and function properly: sectionIndexTitlesForTableView : and sectionForSectionIndexTitle :. In the next tutorial, we'll cover how to add a search bar to this table.
The complete source code for this tutorial can be found here: Indexed UITableView
- IndexedTable.zip (22 KB)
- 下载次数: 5
发表评论
-
Nuance - Dragon Mobile SDK - Speech Kit
2012-07-02 15:57 1372http://dragonmobile.nuancemobil ... -
iOS的开源库和开源项目
2012-06-14 10:54 982http://www.cocoachina.com/iphon ... -
[iOS开发教程-4]Create a UITabBarController from scratch
2012-06-13 15:20 1389http://www.iphonedevcentral.com ... -
[iOS开发教程-3]Create a Detail View Page using UIImageView, UITextView and UILabel
2012-06-13 14:11 2091http://www.iphonedevcentral.com ... -
[iOS开发教程-2]Customize that UIViewCell – Part 1: Using Interface Builder
2012-06-13 13:00 1436http://www.iphonedevcentral.com ... -
[iOS开发教程-1]Hello UITableView!
2012-06-13 11:12 2028http://www.iphonedevcentral.com ... -
Window 7主机与VMware中Mac虚拟机共享文件夹
2012-06-08 23:28 190991. 确保针对Mac虚拟机的VMware Tools的安装 ... -
VMware 8.02虚拟机安装MAC lion 10.7.3教程 附送原版提取镜像InstallESD.iso!
2012-06-08 23:14 6331http://www.winthink.net/thread- ... -
[iOS]深入浅出 iOS 之多线程 NSThread
2012-06-08 15:30 21245http://www.cocoachina.com/bbs/r ... -
Object-C中的Selector概念
2012-06-08 15:25 1053selector可以叫做选择器,其实指的就是对象的方法,也 ... -
CodeBlocks集成Objective-C
2012-06-05 23:35 1160http://www.jxva.com/?act=blog!a ... -
用ultraEdit打造自己的Objective-C IDE for Windows
2012-06-05 21:41 1454http://blog.csdn.net/tomatofly/ ... -
Windows下UltraEdit查看Objective-C代码高亮工具
2012-06-05 21:26 2449http://www.cocoachina.com/bbs/r ... -
Objective-C 编程教程(全)
2012-06-04 23:32 1245http://www.youku.com/playlist_s ... -
iPhone开发学习笔记
2012-06-04 22:15 2625http://blog.csdn.net/huanglx198 ... -
Installing and using GNUstep and Objective-C on Windows
2012-06-04 16:49 1015http://www.techotopia.com/index ... -
GNUStep
2012-06-04 16:45 1213http://www.gnustep.org/ T ... -
Objective C programming in Windows – GNUStep & ProjectCenter
2012-06-04 16:12 1122http://www.jaysonjc.com/program ... -
The Objective-C Programming Language
2012-06-03 19:31 991http://developer.apple.com/libr ...
相关推荐
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
本文档是课题研究的研究报告内含调研以及源码设计以及结果分析
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
多线程应用程序设计.pdf
蚁群算法路径规划matlab
IEC 60695-11-3:2012.pdf
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
python实现的基于蒙特卡洛树搜索的AI黑白棋源码带详细注释.zip python实现的基于蒙特卡洛树搜索的AI黑白棋源码带详细注释.zip python实现的基于蒙特卡洛树搜索的AI黑白棋源码带详细注释.zip python实现的基于蒙特卡洛树搜索的AI黑白棋源码带详细注释.zip python实现的基于蒙特卡洛树搜索的AI黑白棋源码带详细注释.zip python实现的基于蒙特卡洛树搜索的AI黑白棋源码带详细注释.zip python实现的基于蒙特卡洛树搜索的AI黑白棋源码带详细注释.zip
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
孪生神经网络-python源码.zip
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
Android 通过USB与PLC设备通信(USB转串口)
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。