- 浏览: 1517679 次
- 性别:
- 来自: 南京
-
文章分类
- 全部博客 (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/customize-that-uiviewcell-part-1-using-interface-builder/
Customize that UIViewCell – Part 1: Using Interface Builder
If you followed my first tutorial on UITableView (link | source code ), you now have a very simple app that shows a list of DVD titles and clicking any of the titles shows you a detail view page with more information about the DVD. That’s all nice but we really want to make it a little bit prettier. We could display the length of each movie right on the listing page. Also, we have this coverImage field in our data set, let’s use it.
What we want is for our home screen to look like this:
We can accomplish that by customizing UITableViewCell. There are 2 ways of going about it:
- Using Interface Builder
- Programmatically
In reality, you can also choose a hybrid approach where you create some UI elements in the Interface Builder and some programmatically.
Which option to choose?
The two approaches both bring some advantages and disadvantages with them.
Interface Builder
If you decide to go the Interface Builder route, you’ll find it very easy to create and customize your cells. Any subsequent edits can also be done quite easily since you’re simply rearranging elements visually. The downside is speed and performance since the system needs to render each view in a cell individually. If your table view has thousands of rows in it, this may/may not affect the performance of your app, depending how complicated your cell is.
Programmatically
This one involves a lot more work. You are responsible for creating each UI element by hand in the code. That can be very tedious and any edits you need to make in the future require code changes. Also, you’ll need to set up all the autosizing masks yourself. The upside is performance. Since the system will draw each cell as one view, the performance gain can be very significant.
Ok, let’s get to it…
1. Subclass UITableViewCell
Create a Cocoa Touch Class file and make it a subclass of UITableViewCell . Let’s name it DVDListingViewCell.m . We’ll use this class as a placeholder for our labels and the cover image. In DVDListingViewCell.h add the following code:
@interface DVDListingViewCell : UITableViewCell { IBOutlet UILabel *titleLabel; IBOutlet UIImageView *coverImageView; IBOutlet UILabel *featureLengthLabel; } @property (nonatomic, retain) UILabel *titleLabel; @property (nonatomic, retain) UILabel *featureLengthLabel; @property (nonatomic, retain) UIImageView *coverImageView; @end
We use the IBOutlet annotation here to later let Interface Builder know we want to connect these properties with the actual UI elements we’ll lay out.
We also need synthesize the properties we’ve just defined. This will create all setters and getters for us. Add this to DVDListingViewCell.m right below the @implementation directive.
@synthesize titleLabel, featureLengthLabel, coverImageView;
2. Design the cell in Interface Builder
In Xcode, double-click on any of the nib files (they should all be listed under NIB Files magic folder). Once in Interface Builder, choose New… from the File menu. You should be presented a dialog with several templates in it. From the Cocoa Touch category on the left, choose Empty .
You should now see an “Untitled” window with File’s Owner and First Responder in it. One thing missing right now is the actual cell view, let’s add it. From the Library window (Tools -> Library) locate Table View Cell . Drag it to the “Untitled” window. You should now see something like this:
Double clicking on the Table View Cell object will open up the actual cell view where we’re going to add our UI elements. Make the cell 120 pixels in height (you change the dimensions under the size tab in the properties window or by pressing Command + 3 ). Drag a couple Lable s and an Image View to the cell to lay it out as shown below. Once done, save the file as DVDListingView . Make sure to save the file in your project directory and check the checkbox when prompted if you want to add the file into your project.
3. Prepare the RootViewController
Return back to Xcode and open up your RootViewController.h header file. We will add a cell instance variable of type DVDListingViewCell that we’ve created earlier. We will use this cell to actually draw on the screen. Modify your header file to make it look like this:
@interface RootViewController : UITableViewController { DvdLibraryDao *dao; IBOutlet DVDListingViewCell *_cell; }
You may notice the IBOutlet annotation again. That is because we will be connecting this variable to the actual cell we created in Interface Builder.
Let’s switch to the implementation file of our RootViewController (RootViewController.m ). You may remember the method cellForRowAtIndexPath from the first tutorial . That’s the method that controls what cell is drawn at which row. We’ll want our cell to be a DVDListingViewCell so let’s modify the current version of it to this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"LibraryListingCell"; DVDListingViewCell *cell = (DVDListingViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil]; cell = [_cell autorelease]; _cell = nil; } cell.titleLabel.text = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"]; cell.featureLengthLabel.text = [NSString stringWithFormat:@"%@ minutes", [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"featureLength"]]; cell.coverImageView.image = [UIImage imageNamed:[[dao libraryItemAtIndex:indexPath.row] valueForKey:@"coverImage"]]; return cell; }
There are few things going on so let’s analyze them line by line.
Line #5 was changed to initialize the cell local variable to the DVDListingViewCell instead of the generic UITableViewCell .
Lines #6-#10 contain the meat of the cell creation. It first loads the nib file we created. You can see we’re setting the owner to self . That is because the _cell instance variable will get initialized via the nib file, which I’m going to cover a little later.
And finally, Lines #12-#15 assign proper values to the labels and image view in our custom cell.
4. Connect everything in Interface Builder
Return back to Interface Builder and click on the File’s Owner icon. Open up the Identity Inspector (Tools -> Identity Inspector) and look at the Class drop-down menu. Locate RootViewController and select it. In the same window, you should now see the _cell instance variable that belongs to RootViewController . When the nib file is loaded, we’ll want the cell we designed in Interface Builder to be assigned to our _cell . Let’s do that next.
Open up Connections Inspector (Tools -> Connections Inspector) with File’s Owner icon still selected. You should see our _cell in the Outlets section. Next to it is a little hollow circle that turns into a plus (+) sign when you hover it. Click on the circle and drag over to the Listing View Cell window. When you drag over it, the cell should highlight with a label that says “Listing View Cell.” Release the mouse to complete the connection (the cell will blink).
Note: There is an alternate way of creating the connection; Click on the File Owner’s icon while pressing down the Control key and Ctrl-drag to the Listing View Cell icon. A little black pop-up window “Outlets” will appear. Select _cell and let go of the mouse.
Now let’s connect our two labels and the image view. Highlight the Listing View Icon and open up Identity Inspector (Command+4). Under the Class drop-down find and select our DVDListingViewCell . Once done, you should see all the outlets we defined earlier in the DVDListingViewCell class: coverImageView , featureLengthLabel and titleLabel . Open up Connections Inspector (Command+2) and check out the Outlets section. Just as before, drag a connection from the hollow circle next to titleLabel to the “My DVD” label, featureLengthLabel to the feature length label and finally coverImageView to the UIImageView object in our Listing View Cell .
Alternatively, you can Control-drag from the Listing View Cell icon to the Listing View Cell window and connect the three objects that way.
Save all your changes and return back to Xcode.
5. Set the cell height in RootViewController
After you’ve saved your changes in Interface Builder and return back to Xcode, go ahead and run the project. You’ll see that everything works well except one thing – the cells are all crammed together.
This is because we need to explicitly set the height of cells in each row when it differs from the default. We can correct that by implementing the heightForRowAtIndexPath delegate method in the RootViewController.m file.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 120.0; }
Rerun your project and you should now see the cells correctly sized and looking good.
Conclusion
Remember that this is just one of a couple ways to customize your cells. You can do all of this by hand, programmatically which is more work but may result in a better performance. We will cover that in the second part of this tutorial.
You can download the complete source code to this tutorial here: My DVD Library Xcode Project 02 .
- MyDVDLibrary02.zip (95.6 KB)
- 下载次数: 2
发表评论
-
Nuance - Dragon Mobile SDK - Speech Kit
2012-07-02 15:57 1446http://dragonmobile.nuancemobil ... -
iOS的开源库和开源项目
2012-06-14 10:54 1051http://www.cocoachina.com/iphon ... -
[iOS开发教程-5]Create Indexed UITableView
2012-06-13 16:31 1769http://www.iphonedevcentral.com ... -
[iOS开发教程-4]Create a UITabBarController from scratch
2012-06-13 15:20 1458http://www.iphonedevcentral.com ... -
[iOS开发教程-3]Create a Detail View Page using UIImageView, UITextView and UILabel
2012-06-13 14:11 2165http://www.iphonedevcentral.com ... -
[iOS开发教程-1]Hello UITableView!
2012-06-13 11:12 2123http://www.iphonedevcentral.com ... -
Window 7主机与VMware中Mac虚拟机共享文件夹
2012-06-08 23:28 191641. 确保针对Mac虚拟机的VMware Tools的安装 ... -
VMware 8.02虚拟机安装MAC lion 10.7.3教程 附送原版提取镜像InstallESD.iso!
2012-06-08 23:14 6390http://www.winthink.net/thread- ... -
[iOS]深入浅出 iOS 之多线程 NSThread
2012-06-08 15:30 21352http://www.cocoachina.com/bbs/r ... -
Object-C中的Selector概念
2012-06-08 15:25 1130selector可以叫做选择器,其实指的就是对象的方法,也 ... -
CodeBlocks集成Objective-C
2012-06-05 23:35 1223http://www.jxva.com/?act=blog!a ... -
用ultraEdit打造自己的Objective-C IDE for Windows
2012-06-05 21:41 1510http://blog.csdn.net/tomatofly/ ... -
Windows下UltraEdit查看Objective-C代码高亮工具
2012-06-05 21:26 2529http://www.cocoachina.com/bbs/r ... -
Objective-C 编程教程(全)
2012-06-04 23:32 1306http://www.youku.com/playlist_s ... -
iPhone开发学习笔记
2012-06-04 22:15 2713http://blog.csdn.net/huanglx198 ... -
Installing and using GNUstep and Objective-C on Windows
2012-06-04 16:49 1094http://www.techotopia.com/index ... -
GNUStep
2012-06-04 16:45 1269http://www.gnustep.org/ T ... -
Objective C programming in Windows – GNUStep & ProjectCenter
2012-06-04 16:12 1177http://www.jaysonjc.com/program ... -
The Objective-C Programming Language
2012-06-03 19:31 1068http://developer.apple.com/libr ...
相关推荐
Based on the provided information from "iOS 5 Programming Cookbook" by Vandad Nahavandipoor, we can derive a comprehensive set of knowledge points related to iOS development using Objective-C....
毕业论文-叮当活动报名V1.0.0 开源版-整站商业源码.zip
c#随机输出14个字符串代码.zip
内容概要:文章主要探讨了批量工件并行切割下料的问题,重点在于优化切割方案以提高板材利用率、减少切割时间和降低能耗。文中详细介绍了切割机的工作原理及其运动方式,以及对不同尺寸板材(A: 8000*3000、B: 6000*2000、C: 7000*2500)的切割要求。提出了五个任务:一是不考虑约束条件下,为三种板材设计切割排版方案以最大化板材利用率;二是基于四把切割刀具,规划最短时间完成切割的协同运行方案;三是根据附件2提供的工件型号分布,确定切割这批工件所需的板材数量和排版方案,以最大化板材利用率;四是使用八把切割刀具,在保证板材利用率不低于之前方案95%的前提下,最小化切割时间;五是综合考虑板材、设备时间和能量的成本,利用最多十把切割刀具,最小化总成本。;
**描述:“适用于JDK8的环境”** 本文将深入探讨Neo4j社区版3.5.6版本,这是一个基于图数据库的强大工具,特别适用于知识图谱构建和可视化。由于其运行需求,必须在Java Development Kit(JDK)8的环境下进行安装和操作。 **一、Neo4j概述** Neo4j是一款开源的图形数据库,它以节点、关系和属性的形式存储数据,这使得处理复杂网络结构的数据变得更为直观和高效。Neo4j社区版是免费的,适合开发和学习用途,而企业版则提供了更多的高级功能和服务。 **二、JDK8要求** 为了运行Neo4j 3.5.6,你需要在你的计算机上安装JDK8。JDK是Java开发工具包,包含了运行Java应用程序所需的Java虚拟机(JVM)以及一系列开发工具。确保安装的是与Neo4j版本兼容的JDK版本至关重要,因为不兼容的JDK可能会导致运行错误或性能问题。 **三、安装和配置** 1. **下载与解压**: 从官方渠道下载"neo4j-community-3.5.6.zip"压缩文件,并将其解压到你选择的目录。 2. **环境变量配置**: 配置系统环境变量,将Neo4j的bin目录添加到PATH环境变量中,以便于命令行启动和管理数据库。 3. **修改配置文件**: Neo4j的配置主要通过`conf/neo4j.conf`文件进行,如需更改默认设置,如内存分配、端口设置等,应在此文件中进行修改。 4. **启动和停止**: 使用`neo4j console`命令启动服务,`neo4j stop`命令关闭服务。 **四、知识图谱与可视化** Neo4j因其强大的图数据模型,成为构建知识图谱的理想选择。你可以使用Cypher查询语言来操作和查询图数据,它的语法简洁且直观,易于学习。 1. **Cypher语言**: Cypher是一种声明式、图形化
flatbuffers/////
AGV技术详解.pdf
内容概要:本文介绍了Protozoa,一种基于WebRTC的多媒体隐蔽传输工具,旨在帮助用户绕过互联网审查。Protozoa利用WebRTC视频通话作为载体,通过修改WebRTC框架中的编码视频帧来嵌入并传输隐蔽数据。它具有高带宽性能(可达1.4Mbps)和强大的流量分析抗性,能够在不被检测的情况下传输任意IP流量。实验表明,Protozoa可以在不同网络条件下保持稳定性能,并成功绕过中国、俄罗斯和印度的国家级审查机制。 适合人群:对网络安全、隐蔽通信技术感兴趣的科研人员和技术专家,以及需要绕过互联网审查访问受限内容的用户。 使用场景及目标:①适用于希望在受限制网络环境中安全、隐蔽地访问互联网资源的技术人员;②研究和测试新型隐蔽通信方法的研究人员;③评估和改进隐蔽通信系统的安全性和性能。 阅读建议:由于涉及复杂的网络协议和技术细节,建议读者具备一定的计算机网络和编程基础。重点关注Protozoa的工作原理、实现方式及其与现有隐蔽通信工具的比较,以便更好地理解和应用这一技术。
毕业论文-发卡-整站商业源码.zip
实训商业源码-智答-更好用的语音问答6.0.4-毕业设计.zip
实训商业源码-免签码支付源码-毕业设计.zip
毕业论文-房产中介小程序8.0.56+开源版-整站商业源码.zip
毕业论文-活动报名小程序-整站商业源码.zip
ANSYS产品资料——Systems and Multiphysics.pdf
毕业论文-KTV小程序V1.6.1+分销1.0.0带前端-整站商业源码.zip
该项目实现了一个多目标优化算法的集成框架,主要用于求解复杂的多目标优化问题(MOPs)。其核心功能包括以下方面: 1. **多目标优化算法集成** 项目整合了三种经典的多目标优化算法: - **NSGA-II**:基于非支配排序和拥挤度距离的遗传算法,适用于全局搜索。 - **MOPSO**:多目标粒子群算法,通过粒子群协同搜索和外部存档维护Pareto前沿。 - **NSGAMOPSO**:创新性地结合NSGA-II和MOPSO的双种群协同进化策略,兼顾全局探索与局部开发能力。 2. **测试函数库与问题定义** 提供了47个标准多目标测试函数(如ZDT、DTLZ、UF、WFG系列等)和实际工程问题(如盘式制动器设计),支持2-3目标优化,并内置真实Pareto前沿数据用于性能验证。 3. **性能评估指标** 实现了四种评价指标: - **IGD**(反向世代距离):衡量解集与真实Pareto前沿的接近程度。 - **GD**(世代距离):评估解集的收敛性。 - **HV**(超体积):量化解集的多样性和覆盖范围。 - **Spacing**:反映解集分布的均匀性。 4. **可视化与对比分析** 支持二维/三维Pareto前沿的动态绘图,直观对比不同算法的优化效果,并自动生成指标数据表格(如Excel文件),便于量化分析算法性能。 5. **自适应参数与约束处理** 算法参数(如交叉概率、变异概率)可动态调整,同时通过边界检查和修复机制确保解的可行性。 **应用价值**:该项目为研究者和工程师提供了一个高效、可扩展的多目标优化工具,适用于学术研究、工业设计(如机械优化)等领域,能够快速验证算法性能并解决实际多目标优化问题。
AVEVA数字时代的智造方式.pdf
毕业论文-叮咚同城微圈小程序V11.3.3+前端 开源版-整站商业源码.zip
内容概要:文章详细探讨了基于MATLAB/Simulink的电动汽车预充电路设计,旨在解决电动汽车启动及充电初始阶段电池系统承受瞬态大电流冲击的问题。文章首先分析了电动汽车技术的发展背景及预充电路的重要性,接着介绍了预充电路的工作原理、设计要点及相关的技术标准。文中通过构建预充电路的MATLAB/Simulink仿真模型,对比了不同预充电阻值对电流冲击的影响,并引入PID控制策略优化预充电过程。最终,通过多工况仿真验证了设计方案的工程适用性和有效性。研究结果显示,优化后的预充电路可将冲击电流峰值抑制在安全阈值范围内,电压过渡过程的稳定性提升35%以上。 适合人群:具备一定电力电子和控制理论基础的电气工程师、从事电动汽车研发的技术人员、高校相关专业的研究生及科研人员。 使用场景及目标:①研究电动汽车预充电路的动态特性及关键参数优化;②设计智能控制策略以提升充电系统的安全性与效率;③验证预充电路在不同工况下的性能表现,为实际应用提供技术支持。 其他说明:本文不仅提供了详细的理论分析和仿真模型构建方法,还展示了仿真实验的具体步骤和结果,强调了预充电路设计对电动汽车整体性能和安全性的关键作用。研究成果不仅适用于锂离子电池预充场景,其多变量控制思路亦可扩展至钠离子电池、固态电池等新型储能系统的充放电管理领域。