我有兩個視圖控制器,它們都包含表視圖。我想重複使用這些代碼,因爲它們是相同的,並且希望保持清潔(並保留視圖控制器的一些數據)。我怎麼能這樣做呢?這是「允許」這樣說還是皺眉?重用UITableView代碼?
-2
A
回答
0
CustomTableView.h:
@interface CustomTableView : UITableView
@property (nonatomic, strong) NSString *someCoolString;
@property (nonatomic, strong) UIColor *superDuperColor;
@end
CustomTableView.m:
#import "CustomTableView.h"
@implementation CustomTableView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
self.someCoolString = @"theString";
self.superDuperColor = [UIColor colorWithRed:48.0/255.0 green:32.0/255.0 blue:100.0/255.0 alpha:1.0];
}
return self;
}
@end
0
相關問題
- 1. UITableView中的重複代碼
- 2. 用代碼添加UITableView代碼
- 3. 的UITableView reloadData EXC_BAD_ACESS代碼= 2
- 4. 從代碼中查找UITableView?
- 5. UITableView - 從ViewWillAppear訪問代碼
- 6. UITableview的錯誤代碼SWIFT
- 7. UITableView的僞影在代碼
- 8. UITableView - didSelectRowAtIndexPath中的代碼不起作用
- 9. 代碼重用和重構
- 10. Spreadhseet代碼重用
- 11. 重用jQuery代碼?
- 12. JSP代碼「重用」
- 13. Android代碼重用的java代碼
- 14. ios,代碼重用問題,重用viewController?
- 15. 重用JavaScript代碼(減少重複代碼)
- 16. UITableView在UITableViewController代碼中添加UIView
- 17. UITableView顯示代碼中的錯誤
- 18. UITableView比代碼中的全屏少?
- 19. 從代碼中插入UITableView行
- 20. UITableView:當tableFooterView顯示時運行代碼?
- 21. 重用CSS代碼更少
- 22. 重寫代碼棄用
- 23. 如何「重用」XSL代碼
- 24. 無代碼的Html重用
- 25. 重用代碼的RelayCommand
- 26. c#代碼重用性
- 27. 代碼重用,線程級
- 28. 可重複使用代碼
- 29. 重用活動代碼
- 30. 如何重用代碼
創建自定義的tableView所有者yourseft –
你應該閱讀有關'面向對象programming'。 – Desdenova
感謝以上。我對這兩者都很熟悉,我或多或少地問,是否有一個好方法可以解決這個問題。不太熱衷於製作自定義視圖。來自Java背景,所以我想確保在做事情時我開始更多地考慮MVC模型。 – David