我具有其中我有兩個的tableview控制器的應用程序。在第一個tableview控制器中,當第二行被選中時,一個新的tableview被載入7行。使用localizablestrings的以滿足特定條件,並顯示特定字符串
該tableview的行中的值是通過使用一個NSMutableArray填充的,其中靜態地存儲了7個值,然後我在no of rows方法中返回了該數組。在這個控制器的didselect方法中,我調用一個調用localizable.strings文件的方法,並依賴於我的條件返回第一個tableview控制器的詳細信息上的字符串。在第二個控制器中,我有每行7行的tableview,每行的值爲「Every Monday」,「Every Tuesday」,「Every Wednesday」,「Every Thursday」,「Every Friday」,「Every Saturday」,「Every Sunday」。
當我點擊特定行時,該特定行的值必須顯示在第一個控制器的詳細文本中。
當我點擊第5行從週一即到週五必須顯示第一個控制器的detailtext「每工作日」的值。
當我點擊最後2行,即星期六&星期日時,必須在第一個控制器的詳細文本上顯示「Every Weekends」的值。
當我點擊任何隨機行,即週一,週三,週四時,必須在第一個控制器的詳細信息上顯示「Every Mon,Wed,Thu」的值。
這是我的第二個控制器的代碼,我選擇我的手機:
#import "TAlarmNewController.h"
//#import "global.h"
#import "TAddAlarmController.h"
#import "global.h"
#import "Alarm.h"
#import <sqlite3.h>
#define DATABASE_NAME @"Alarmcheck.sqlite"
#define DATABASE_TITLE @"Alarmcheck"
@implementation TAlarmNewController
@synthesize editedObject,datePicker, tblView,daysarray,Addalarm,rowselection,temp, mins, secs, weekday, dayOfMonth, month, year,repeat,Alarmid;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
daysarray =[[NSMutableArray alloc]initWithObjects:@"Every Monday",@"Every Tuesday",@"Every Wednesday",@"Every Thursday",@"Every Friday",@"Every Saturday",@"Every Sunday",nil];
temp = [[NSDictionary alloc] initWithObjectsAndKeys:daysarray,@"arrValue",nil];
arrayValues = [[NSMutableArray alloc] initWithObjects:@"Every Monday",@"Every Tuesday",@"Every Wednesday",@"Every Thursday",@"Every Friday",@"Every Saturday",@"Every Sunday",nil];
//self.daysarray = arrayValues;
counter = 0;
//[arrayValues release];
[super viewDidLoad];
}
- (TAddAlarmController *)Addalarm {
if (Addalarm == nil) {
Addalarm = [[TAddAlarmController alloc] initWithStyle:UITableViewStyleGrouped];
}
return Addalarm;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [arrayValues count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [daysarray objectAtIndex:indexPath.row];
cell.accessoryType = ([indexPath isEqual:rowselection]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
cell.detailTextLabel.textColor = [UIColor redColor];
//return cell;
// Configure the cell...
return cell;
}
//this is localization code.
-(void)selectmultiplerows
{
newrepeat = [[NSString alloc]retain];
if (!repeat)
{
BOOL mon = [self.arrayValues objectAtIndex:1] != nil;
BOOL tue = [self.arrayValues objectAtIndex:2] != nil;
BOOL wed = [self.arrayValues objectAtIndex:3] != nil;
BOOL thu = [self.arrayValues objectAtIndex:4] != nil
BOOL fri = [self.arrayValues objectAtIndex:5] != nil;
BOOL sat = [self.arrayValues objectAtIndex:6] != nil;
BOOL sun = [self.arrayValues objectAtIndex:0] != nil;
if (mon && tue && wed && thu && fri && sat && sun) {
newrepeat = NSLocalizedString(@"everyday",@"Alarm description");
}
else if (mon && tue && wed && thu && fri) {
newrepeat = NSLocalizedString(@"every week days",@"Alarm description");
}
else if (sat && sun){
newrepeat = NSLocalizedString(@"every weekends",@"Alarm description");
}
else if (mon || tue || wed || thu || fri || sat || sun) {
//TODO
//newrepeat = NSLocalizedString(@"",@"Alarm description");
if (mon) {
//newrepeat = [newrepeat stringByAppendingFormat:NSLocalizedString(@"monday",@"Alarm description")];
newrepeat = NSLocalizedString(@"monday",@"Alarm description");
}
if (tue) {
newrepeat = NSLocalizedString(@"tuesday",@"Alarm description");
//newrepeat = [newrepeat stringByAppendingFormat:NSLocalizedString(@"tuesday",@"Alarm description")];
}
if (wed) {
newrepeat = NSLocalizedString(@"wednesday",@"Alarm description");
//newrepeat = [newrepeat stringByAppendingFormat:NSLocalizedString(@"wednesday",@"Alarm description")];
}
if (thu) {
newrepeat = NSLocalizedString(@"thursday",@"Alarm description");
//newrepeat = [newrepeat stringByAppendingFormat:NSLocalizedString(@"thursday",@"Alarm description")];
}
if (fri) {
newrepeat = NSLocalizedString(@"friday",@"Alarm description");
//newrepeat = [newrepeat stringByAppendingFormat:NSLocalizedString(@"friday",@"Alarm description")];
}
if (sat) {
newrepeat = NSLocalizedString(@"saturday",@"Alarm description");
//newrepeat = [newrepeat stringByAppendingFormat:NSLocalizedString(@"saturday",@"Alarm description")];
}
if (sun) {
newrepeat = NSLocalizedString(@"sunday",@"Alarm description");
//newrepeat = [newrepeat stringByAppendingFormat:NSLocalizedString(@"sunday",@"Alarm description")];
}
//remove extra comma
if ([newrepeat hasSuffix:@", "]) {
newrepeat = [newrepeat stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
}
}
else
{
newrepeat = NSLocalizedString(@"tuesday",@"Alarm description");
}
}
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
cell = [tableView cellForRowAtIndexPath:indexPath];
cell.detailTextLabel.textColor = [UIColor blackColor];
if ([[tableView cellForRowAtIndexPath:indexPath ] accessoryType] == UITableViewCellAccessoryCheckmark)
{
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
[self.arrayValues replaceObjectAtIndex:row withObject:@"0"];
cell = [tableView cellForRowAtIndexPath:indexPath];
newrepeat = [NSString stringWithFormat:@"%@",cell];
}
else
{
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
[self.arrayValues replaceObjectAtIndex:row withObject:@"1 "];
cell = [tableView cellForRowAtIndexPath:indexPath];
}
[self selectmultiplerows];
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[datePicker release];
[super dealloc];
}
@end
最後我設置了newrepeat這是爲h我的第一個控制器的cellForRowAtIndexPath一個全局變量。但問題是我的狀況沒有得到滿足。可能是什麼問題?
通過改變選擇multiplerows的代碼,現在直接進入第一個if條件,並返回「天天向上」每次如果我選擇1個特定行也。
有太多的代碼在這裏,有的七年後給出的問題的國家(特別是段落細節的代碼塊藏在裏面),我認爲這是無法回答的,並且拋棄。現在投票結束。 – halfer