要实现跟iphone主界面一样的宫格视图,应该怎么做呢?就是每一宫格带一个icon图标和一行文字,同时可以响应事件!希望哪位大侠指点指点一二,最好能贴段代码,嘿嘿,十分感谢!刚学习iphone,一头的雾水,汗!也可以发到   再三感谢!

解决方案 »

  1.   

    iPhone UITableView(利用UITableView实现平滑的九宫格效果
    UITableView是一种“目录视图或叫表视图”(英文名字table view),这种表视图以列表的形式显示或编辑信息,它由一列、多行组成。用户可以通过垂直滚动的方式导航到一个表视图的任意行上,并可以自定义每一行数据的显示方式。在创建表视图的时候,可以选择两种风格的表视图:UITableViewStylePlain或者UITableViewStyleGrouped,前者是按索引进行排序的,而后者是按组进行分类显示的。基本上每一个UITableView都有相应的UITableViewController、UITableViewDelegate、UITableViewDataSource类。UITableViewController类作为UITableView的视图控制类(MVC里Controller的角色)负责管理UITableView,它和大多数UIViewController类一样,控制着UITableView的生命周期函数。UITableViewDelegate作为委托模式里的被委托对象的接口,和大多数iPhone委托接口一样,它提供了UITableView子类无法在行为上保持一致的部分,在这里读者可以自定义表视图的显示风格,甚至可以自定义表视图的每一个元素,它的重要接口定义如下:@protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
    @optional// Display customization
    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;// Variable height support
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;// Section header & footer information. Views are preferred over title should you decide to provide both
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; 
    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // Accessories (disclosures). 
    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;// Selection
    // Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.
    - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;// Called after the user changes the selection.
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;// Editing
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;// Indentation
    -(NSInteger)tableView:(UITableView *)tableViewindentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath; // return'depth' of row for hierarchies@endUITableViewDataSource提供了表视图的数据源,下表列出了常见的表视图数据源方法:
    Method
     Description
     
    tableView:numberOfRowsInSection:
     特定Section内的行数
     
    numberOfSectionsInTableView:
     特定数据源的表视图的Section数目
     
    tableView:cellForRowAtIndexPath:
     从数据源获取单元格内容并放到特定的行上
     
    sectionIndexTitlesForTableView:
     获取一个数据源的表视图的标题
     
    tableView:commitEditingStyle:forRowAtIndexPath
     提交单元格内容的修改
     
    talbeView:canEditRowAtIndexPath:
     通过返回一个Boolean类型的值来通知表视图某一行能否修改
     
    tableView:canMoveRowAtIndexPath:
     通过返回一个Boolean类型的值来通知表视图某一行能否被移动
     
    tableView:moveRowAtIndexPath:toIndexPath:
     允许某一个表视图单元格被移动
     表视图数据源接口提供了表视图数据源操作的常用方法,其中tableView:numberOfRowsInSection和tableView:cellForRowAtIndexPath:是每一个表试图的数据源必须实现的两个方法,前者告诉表视图内有多少行单元格,而后者告诉表视图每一个单元格的内容是什么。程序通过实现这两个方法,可以提供一个表视图所需要的基本信息并供表视图调用。笔者在下面的例子里会编写一个带导航面板的表视图,这种复杂类型的控件在iPhone中随处可见,如iPod程序、备忘录程序、闹钟程序等。ü 首先,新建一个“Window-based”项目并命名为“TableProjectOne”。
    ü 新建一个UIViewController的子类,并命名为“MyViewController”。
    ü 创建一个空的xib并命名为“MyViewController”。
    ü 在Interface Build中打开MyViewController.xib。
    ü 从Library里拖拉一个view到MyViewController的窗口中,然后再添加一个table view到新添加的view下,确保table view完全填充view。
    ü 修改File’s Owner为MyViewController,连接MyViewController的view到上面新添加的view上。
    ü 到这里MyViewController创建完毕,保存并退出Interface Build。
    ü 打开MainWindow.xib并拖拉一个Navigation Controller到窗口中。
    ü 拖拉一个View Controller到Navigation Controller下,改变它的类名和Nib名为MyViewController。
    ü 拖拉一个Bar Button Item到Navigation Controller上,并改title为“view2”。修改TableProjectOneAppDelegate.h文件如下:#import <UIKit/UIKit.h>
    #import "MyViewController.h"@interface TableProjectOneAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    IBOutlet UINavigationController *viewController;
    }@property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UINavigationController *viewController;@end实现文件TableProjectOneAppDelegate.m如下:#import "TableProjectOneAppDelegate.h"@implementation TableProjectOneAppDelegate@synthesize window;
    @synthesize viewController;- (void)applicationDidFinishLaunching:(UIApplication *)application { 
    [window addSubview:self.viewController.view];
    // Override point for customization after application launch
    [window makeKeyAndVisible];
    }- (void)dealloc {
    [window release];
    [viewController release];
    [super dealloc];
    }
    @end
      

  2.   

    http://madhome.org/simple/?t1145.html
      

  3.   

    最简单快捷的方式就是在一个view上加9个button就可以了。
    就是一个主菜单的情况下,这种做法高效快捷。
      

  4.   

    直接加button试过,嘿嘿,但手机旋转的时候,视图不怎么好看,不过谢谢各位!UITableView我也试过,只不过刚学这个,不善于利用这些方法,画出来的九宫格其实就是三行,我点击一下,就选中了一行,就将其中的三宫格给选中了,而且界面也不好看!能贴个现实的九宫格的代码吗?嘿嘿
      

  5.   

    旋转屏的时候动态控制按钮的location阿。或者直接设计两个view,横竖屏分开设计显示。
    后台处理共通。
      

  6.   

    直接采用了Qim的办法,解决了,汗!但用UITableView还没解决,郁闷,谢谢了!