我創建的字體列表通過tableView,當用戶選項卡的任何單元格的字符串應根據單元格更改,但我不知道爲什麼我的代碼不起作用! 我的tableview與UIPopOverViewContoller打開:這裏是我的代碼:iOS didSelectRow和setString
.H
@interface FontViewController : UITableViewController <UITableViewDelegate , UITableViewDataSource , UINavigationControllerDelegate> {
NSMutableArray *listOfFonts;
}
@property (nonatomic, retain) NSMutableArray *listOfFonts;
.M
#import "FontViewController.h"
#import "xxxAppDelegate.h"
#import "xxxViewController.h"
@implementation FontViewController
- (void)viewDidLoad
{
listOfFonts = [[NSMutableArray alloc] init];
[listOfFonts addObject:@"font1"];
[listOfFonts addObject:@"font2"];
[listOfFonts addObject:@"font3"];
[listOfFonts addObject:@"font4"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//TableView Codes ....
cell.textLabel.text = [listOfFonts objectAtIndex:indexPath.row];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
xxxAppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
appDelegate.viewController.detailItem = [listOfFonts objectAtIndex:indexPath.row];
}
xxxViewController.h:
@interface {
NSString *fontString;
id detailItem;
}
@property (nonatomic ,retain) NSString *fontString;
@property (nonatomic, retain) id detailItem;
xxxViewController.m:
@synthesize detailItem ,fontString;
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];
//---update the view---
fontString = [detailItem description];
}
}
//here is the custom font codes : (I am using special fonts which does not works with UIApplicationFont in app plist)
(CTFontRef)newCustomFontWithName:(NSString *)fontName
ofType:(NSString *)type
attributes:(NSDictionary *)attributes
{
// the string of cell should be equal to the pathForResource:fontString for example font1 , font 2 ...
NSString *fontPath = [[NSBundle mainBundle] pathForResource:fontString = [detailItem description] ofType:@"ttf"];
NSData *data = [[NSData alloc] initWithContentsOfFile:fontPath];
CGDataProviderRef fontProvider = CGDataProviderCreateWithCFData((CFDataRef)data);
[data release];
/// blah alah blah
}
這裏是setDetailItem調試信息
NSLog(@"fontString: %@, assigned: %@ in controller: %@", fontString, [detailItem description], self);
2011-10-02 23:12:57.036 Medad[558:10d03] fontString: (null), assigned: font1 in controller: < myAppViewController: 0x7078a30>
2011-10-02 23:12:58.015 Medad[558:10d03] fontString: (null), assigned: font2 in controller: < myAppViewController: 0x7078a30>
2011-10-02 23:12:58.475 Medad[558:10d03] fontString: (null), assigned: font3 in controller: < myAppViewController: 0x7078a30>
2011-10-02 23:13:00.365 Medad[558:10d03] fontString: (null), assigned: font4 in controller: < myAppViewController: 0x7078a30>
我的問題是這樣的一行: 的FontString這應該改變小區選擇...
NSString *fontPath = [[NSBundle mainBundle] pathForResource:???fontString????? ofType:@"ttf"];
,我將不勝感激,如果有人幫助我感謝
「我的密碼不起作用!」沒有幫助,請解釋在哪裏以及哪些方面無法解決問題。如果可能,請提供來自GDB的錯誤消息。 – chown
沒有任何錯誤和警告或崩潰:)只是當我選擇一個單元格的字符串不會改變它意味着不會改變字體 –
我還會讓你注意到你將detailItem設置爲NSString「font1」或別人,所以你可以直接設置fontString屬性。沒有必要指定一個字符串,然後調用[description]來獲取相同的字符串。 – Zmaster