- 浏览: 1481548 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (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/create-a-detail-view-page-using-uiimageview-uitextview-and-uilabel/
Create a Detail View Page using UIImageView, UITextView and UILabel
I’m going to build this tutorial on the previous two so if you haven’t checked them out yet, you can see the first one here and the second one here . You can also download the source code on the bottom of each tutorial.
What we’ve done so far
We used UITableViewController to build out our root view controller that lists all the DVDs from our data file. Then we customized each cell by adding a DVD cover and some basic info about each movie. Tapping a row in the table caused the app to go to a detail page which was also a table displaying expanded info about the selected movie. That’s the part we’re going to work on now.
1. Download some source code to get your started
Since we’re going to be completely removing the detail view controller we used in the previous tutorials, let’s just start from there. Instead of walking you through deleting the controller and removing the appropriate functionality, download this source code that will get you started. You’ll get the root view controller with customized cells in it. However, tapping on any of the rows won’t do anything, yet. Download the primer project here: MyDVDLibrary03Primer .
2. Enhance test data file
Since our test data file only contains title, length, image and release date for each movie, that’s not going to cut it when trying to design a detail view page. We’ll at least want to add the description of the movie and maybe also its genre. This can be very tedious to do in a plist like we’re using right now but it will get a lot easier once we start using Core Data that I will cover in later tutorials.
I won’t make you add all the data by hand so for a shortcut, download the completed plist file here and replace your existing one that can be found in Xcode under the Resources folder: TestData.plist .
3. Create new DetailViewController class
In Xcode’s file browser on the left, right-click on the Classes folder and choose Add -> New File… . Under Cocoa Touch Classes group choose UIViewController subclass and make sure to check the With XIB for user interface checkbox. This will not only create our subclass but also the NIB file that we’ll use to layout our UI components.
4. Set up UI outlets
We now need to set up all properties in our controller that will be used on the detail view page. There will be an image view for the DVD cover, a label for the title, release date, length, genre and a text view for the description. Add this to the header file of the DetailViewController (DetailViewController.h ):
@interface DetailViewController : UIViewController { IBOutlet UIImageView *coverImageView; IBOutlet UILabel *titleLabel; IBOutlet UILabel *releaseDateLabel; IBOutlet UILabel *lengthLabel; IBOutlet UILabel *genreLabel; IBOutlet UITextView *descriptionTextView; } @property (nonatomic, retain) UIImageView *coverImageView; @property (nonatomic, retain) UILabel *titleLabel; @property (nonatomic, retain) UILabel *releaseDateLabel; @property (nonatomic, retain) UILabel *lengthLabel; @property (nonatomic, retain) UILabel *genreLabel; @property (nonatomic, retain) UITextView *descriptionTextView; @end
Synthesize the properties in the implementation file (DetailViewController.m ):
@synthesize coverImageView, titleLabel, releaseDateLabel, lengthLabel, genreLabel, descriptionTextView;
5. Lay out and connect UI components in Interface Builder
Before we jump to Interface Builder make sure to save all the changes so that IB can pick up on them.
In Xcode, locate DetailViewController.xib file (it got created this file along with DetailViewController class in Step#3) and double-click on it. Once Interface Builder opens you should see an empty canvas where we’re going to place our UI elements. Lay them out as shown in the screenshot below. Note that you should uncheck Editable checkbox on your text view so that the text is read-only.
Now we need to connect the UI elements to its variable counterparts. I’m not going to cover step-by-step how to do that as it has been discussed in some detail in the tutorial on customizing view cells . Please, review that tutorial if you’re unclear how to follow the next set of instructions.
Click on File’s Owner icon to highlight it. From the file menu choose Tools -> Connections Inspector (Cmd + 2). Under Outlets , you’ll see all of our instance variables we declared in the DetailViewController class. Control-drag from File’s Owner to each UI component in the view to connect coverImageView to Image View , releaseDateLabel to Release Date label, genreLabel to Genre label, etc. Once done, your Connections Inspector should be set up like this:
Save your changes and return back to Xcode.
6. Prepare DetailViewController to read test data
If you recall what we did with the original DetailViewController when it was still a table, in its initialization method we passed in a dictionary containing all the info about our DVD library. This was read in using DvdLibraryDao object that basically took the plist we constructed earlier and put all its content into a dictionary. We’re going to do the same thing in our new DetailViewController , only we’re now adding a couple of properties (genre, description) that we just added in Step#2.
We also add declaration of our custom initialization method here. It’s pretty much just a modified initWithNibName method that adds dvdData into the mix. This method will set the local instance variable dvdData that is also declared here. Change DetailViewController.h header file to look like this:
@interface DetailViewController : UIViewController { IBOutlet UIImageView *coverImageView; IBOutlet UILabel *titleLabel; IBOutlet UILabel *releaseDateLabel; IBOutlet UILabel *lengthLabel; IBOutlet UILabel *genreLabel; IBOutlet UITextView *descriptionTextView; NSDictionary *dvdData; } @property (nonatomic, retain) UIImageView *coverImageView; @property (nonatomic, retain) UILabel *titleLabel; @property (nonatomic, retain) UILabel *releaseDateLabel; @property (nonatomic, retain) UILabel *lengthLabel; @property (nonatomic, retain) UILabel *genreLabel; @property (nonatomic, retain) UITextView *descriptionTextView; - (id)initWithDvdData:(NSDictionary *)dvdData nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; @end
Switch over to DetailViewController.m implementation file. Let’s implement the initWithDvdData method:
- (id)initWithDvdData:(NSDictionary *)data nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { dvdData = data; } return self; }
All this is doing is it assigns data that is passed in to our instance variable dvdData .
To read everything in from dvdData to all of the UI elements, we’ll insert a little snippet of code in the viewDidLoad delegate method. As you can see, we assign each value from dvdData to its corresponding UI element.
- (void)viewDidLoad { coverImageView.image = [UIImage imageNamed:[dvdData valueForKey:@"coverImage"]]; titleLabel.text = [dvdData valueForKey:@"title"]; releaseDateLabel.text = [NSString stringWithFormat:@"%@", [dvdData valueForKey:@"releaseDate"]]; lengthLabel.text = [NSString stringWithFormat:@"%@ minutes", [dvdData valueForKey:@"featureLength"]]; genreLabel.text = [dvdData valueForKey:@"genre"]; descriptionTextView.text = [dvdData valueForKey:@"description"]; [super viewDidLoad]; }
7. Handle didSelectRowAtIndexPath in RootViewController
Now that we have our detail view controller all ready to go, let’s connect the dots and have the RootViewController go to the detail page when a row is tapped.
In RootViewController.m, locate the didSelectRowAtIndexPath method. Just as we did before, we’ll instantiate DetailViewController here and push it to the controller stack:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DetailViewController *controller = [[DetailViewController alloc] initWithDvdData:[dao libraryItemAtIndex:indexPath.row] nibName:@"DetailViewController" bundle:[NSBundle mainBundle]]; controller.title = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"]; [self.navigationController pushViewController:controller animated:YES]; [controller release]; }
If everything went well, you should be able to run your project and get something like this:
8. Format the release date field
While something like 2007-07-08 16:32:07 -0700 is completely acceptable by me, many people want to see something a bit more user friendly. Let’s take that date and try to display it as July 8, 2007 . We’re going to achieve that using a nifty utility class called NSDateFormatter. Open DetailViewController.m and change viewDidLoad method to look like this:
- (void)viewDidLoad { coverImageView.image = [UIImage imageNamed:[dvdData valueForKey:@"coverImage"]]; titleLabel.text = [dvdData valueForKey:@"title"]; lengthLabel.text = [NSString stringWithFormat:@"%@ minutes", [dvdData valueForKey:@"featureLength"]]; genreLabel.text = [dvdData valueForKey:@"genre"]; descriptionTextView.text = [dvdData valueForKey:@"description"]; // Format date we get from releaseDate field to more readable form NSDate *releaseDate = (NSDate *)[dvdData valueForKey:@"releaseDate"]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"MMMM d, YYYY"]; releaseDateLabel.text = [dateFormatter stringFromDate:releaseDate]; [super viewDidLoad]; }
All we had done is gave our formatter a string representation of the date format we want and then outputted that date to releaseDateLabel .
Conclusion
When customizing your detail views, possibilities are endless. You could add a texture to your background, add more images, maybe a table with some detailed information, or other controls that would take you forward in the controller stack. But I hope this tutorial got you started and showed you some basic techniques and tricks to create a detail page.
You can download the complete source code to this tutorial here: My DVD Library Tutorial 3
- MyDVDLibrary03Primer.zip (92.6 KB)
- 下载次数: 2
- MyDVDLibrary03.zip (99.8 KB)
- 下载次数: 1
发表评论
-
Nuance - Dragon Mobile SDK - Speech Kit
2012-07-02 15:57 1368http://dragonmobile.nuancemobil ... -
iOS的开源库和开源项目
2012-06-14 10:54 982http://www.cocoachina.com/iphon ... -
[iOS开发教程-5]Create Indexed UITableView
2012-06-13 16:31 1705http://www.iphonedevcentral.com ... -
[iOS开发教程-4]Create a UITabBarController from scratch
2012-06-13 15:20 1387http://www.iphonedevcentral.com ... -
[iOS开发教程-2]Customize that UIViewCell – Part 1: Using Interface Builder
2012-06-13 13:00 1434http://www.iphonedevcentral.com ... -
[iOS开发教程-1]Hello UITableView!
2012-06-13 11:12 2025http://www.iphonedevcentral.com ... -
Window 7主机与VMware中Mac虚拟机共享文件夹
2012-06-08 23:28 190981. 确保针对Mac虚拟机的VMware Tools的安装 ... -
VMware 8.02虚拟机安装MAC lion 10.7.3教程 附送原版提取镜像InstallESD.iso!
2012-06-08 23:14 6328http://www.winthink.net/thread- ... -
[iOS]深入浅出 iOS 之多线程 NSThread
2012-06-08 15:30 21243http://www.cocoachina.com/bbs/r ... -
Object-C中的Selector概念
2012-06-08 15:25 1051selector可以叫做选择器,其实指的就是对象的方法,也 ... -
CodeBlocks集成Objective-C
2012-06-05 23:35 1158http://www.jxva.com/?act=blog!a ... -
用ultraEdit打造自己的Objective-C IDE for Windows
2012-06-05 21:41 1452http://blog.csdn.net/tomatofly/ ... -
Windows下UltraEdit查看Objective-C代码高亮工具
2012-06-05 21:26 2446http://www.cocoachina.com/bbs/r ... -
Objective-C 编程教程(全)
2012-06-04 23:32 1244http://www.youku.com/playlist_s ... -
iPhone开发学习笔记
2012-06-04 22:15 2622http://blog.csdn.net/huanglx198 ... -
Installing and using GNUstep and Objective-C on Windows
2012-06-04 16:49 1013http://www.techotopia.com/index ... -
GNUStep
2012-06-04 16:45 1212http://www.gnustep.org/ T ... -
Objective C programming in Windows – GNUStep & ProjectCenter
2012-06-04 16:12 1119http://www.jaysonjc.com/program ... -
The Objective-C Programming Language
2012-06-03 19:31 988http://developer.apple.com/libr ...
相关推荐
iOS控件 -- UIImageView使用详解,博客地址http://blog.csdn.net/wenxiangjiang/article/details/43151867
它基本上满足你日常大部分需求,不管是一行一个UILabel还是2个UILabel,或者是一个UIImageView或者2个,或者UILabel与UIImageView组合,只要你想的到的,HXFlexoView都可以满足你.如果你觉得对你有用,记得给点个赞哦,谢谢...
一个单手手势旋转放大的自定义View,可以添加UIImageView,UILabel作为其contentView,实现其delegate,可以实现UILabel在放大的同时字体也放大 github地址:https://github.com/ws00801526/XMNViews
JTImageLabel, 在iOS上,JTImageLabel同时保留UILabel和 UIImageView JTImageLabel JTImageLabel是一个简单的视图,它包含一个 UILabel 和一个 UIImageView,即使你更改了 UILabel的对齐方式。安装使用 CocoaPods...
詹姆斯-IOS-Label 可以拉伸,旋转的简单UIImageView和UILabel。 它可以用于tableview单元格或视图中的订单/交易状态。
UIImageView帧动画
UIImageView 的api 和iOS7下的手势api 的使用
iOS-图片-幻灯片基于 UIImageView 子类的图像幻灯片。如何使用特性名称类型描述图片可变数组它表示将在幻灯片上显示的一组图像名称或远程图像 url(例如 google 图像、panoramio 等) 间隔整数幻灯片的计时器间隔...
支持 CocoaPods! pod 'LCBlur' GitHub:https://github.com/iTofu/LCBlur 请在 GitHub 上查阅,以保证版本最新! 有问题请移步 GitHub!这里提问我收不到! (之前发过一次,效果没讲清楚,貌似不...)
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xxx"]]; return imageView; } 【更多说明请前往Github: https://github.com/zzyspace/ZYBannerView/】
iOS开发之UIlabel多行文字自动换行 (自动折行) UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, ...
ScratchImage是可刮擦的UIImageView
ios uiimageview event
具体使用方法:https://blog.csdn.net/qq_33608748/article/details/82495758
UIImageView、UIImageView基本用法、UIImageView详解,UIImageView常用方法
3. Constructing and Using Table Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 3.1 Instantiating a Table View 281 3.2 Assigning a Delegate to a Table View 284 ...
iOS开发,自己封装的一个类,用于开发中要做图片点击放大缩小的功能,导入头文件后直接使用!
IOS中利用UIImageView控件实现gif图片动画显示,借助ImageIO接口达到gif图片拆分效果,然后使用UIImageView动画接口播放一组图片达到动画效果; 最后将单个gif图片动画播放接口封装成UIView类,达到多个gif图片错开...