我已经看到了很多关于片段的问题,我似乎仍然无法弄清楚我想做的事情是否可行,如果我的设计模式有缺陷,我需要重新完成整个工作.处理.基本上,就像大多数问题一样,我有一个带有NavigationTabs的ActionBar(使用ActionBarSherlock),然后在每个Tab中有一个FragementActivity,然后FragmentActivities在选择一行时推送新的Fragments(我正在尝试重新创建) Android中的iOS项目,它只是一个基于导航的基本应用程序,其中包含一些可以深入查看特定信息的选项卡.当我单击手机上的后退按钮时,前一个片段已加载,但片段重新创建(因此每个视图再次调用WebServices),因为在以前的视图中信息不会改变,所以不需要这样做.倒退.所以基本上我想弄清楚的是如何设置我的片段,这样当我按下手机上的后退按钮时,之前的片段就会被拉上前面已经创建的项目.以下是我目前的代码:
//This is from my FragmentActivity Class that contains the ActionBar and Tab Selection Control
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
int selectedTab = tab.getPosition();
if (selectedTab == 0) {
SalesMainScreen salesScreen = new SalesMainScreen();
ft.replace(R.id.content, salesScreen);
}
else if (selectedTab == 1) {
ClientMainScreen clientScreen = new ClientMainScreen();
ft.replace(R.id.content, clientScreen);
}.....
//This is within the ClientMainScreen Fragment Class, which handles moving to the Detail Fragment
row.setOnClickListener(new View.OnClickListener() {
@Override
public void …Run Code Online (Sandbox Code Playgroud) 因此,在我的通用应用程序中,我有一个部分,其中一个人可以查看我们系统中的现有笔记列表(通过简单的Web服务检索),然后如果需要也可以创建一个新笔记.所以对于iPhone而言,它的布局非常简单,一个TableViewController用于在NavigationBar上显示带有"添加"按钮的列表,该按钮显示添加新项目的模态视图.虽然在iPad上,相同的布局有很多浪费的空间,所以我选择使用popOver方法在popOver中显示列表,然后让它们从那里添加.我的问题是当用户点击PopOver视图中的Add按钮时,模态视图会全屏显示,而不是仅仅出现在popover视图中.这是我到目前为止的代码:
-(void) AddButtonPressed:(id)sender {
NewNoteVC *newNote = [[[NewNoteVC alloc] initWithNibName:@"NewNoteVC" bundle:nil] autorelease];
newNote.defaultClientID = defaultClientID;
UINavigationController *navCon = [[[UINavigationController alloc] initWithRootViewController:newNote] autorelease];
if ([isPopOver isEqualToString:@"YES"]) {
[navCon setModalInPopover:YES];
[self.navigationController setModalInPopover:YES];
[self.navigationController presentModalViewController:navCon animated:YES];
}
else {
[self.navigationController presentModalViewController:navCon animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
}
"isPopOver"字符串只是从前一个屏幕发送的占位符,它调用了这个TableView(我知道我可以将其切换为布尔值以获得更好的性能,我只是快速地将它们放在一起试试).我知道我搞砸了某个地方,我只是不知道我需要什么设置才能让它正常工作.
所以我想在我的iOS应用程序中只显示从我们的服务器传递的时间,但是我无法弄清楚如何设置正确的NSDateFormatter.所以例如我以这种格式从服务器获取这个时间戳:2013-02-27T18:15:00-0800,我基本上想在标签上显示"10:15 AM"但到目前为止我还没有任何运气.我试过这个:
NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc] init] autorelease];
[timeFormatter setDateFormat:@"HH:mm a"];
NSString *newTime = [timeFormatter stringFromDate:timeDate];
NSLog(@"the new time is: %@", newTime);
Run Code Online (Sandbox Code Playgroud)
但输出显示我的时间是18:15 PM.
我一直在环顾四周,尝试在NSDateFormatter中使用不同的组合,但我似乎无法找到合适的组合,任何帮助都会受到赞赏,因为我知道这是一个简单的我忽略但我找不到它.
所以我一直在和Android应用程序一起在顶部有一个带有几个Tabs的导航栏,这部分工作正常但现在我希望能够从不同的片段动态添加菜单项到Action Bar(因为一些片段可能有不同的选项).到目前为止,无论我尝试过什么,我似乎都无法调用onCreateOptionsMenu.这是我到目前为止所拥有的
//First I have a holder class that is used to navigate between the different Fragment Tabs
public class ActionHolder extends SherlockFragmentActivity implements ActionBar.TabListener {....
//And then I have this method for switching Fragments based on what Tab is selected
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
int selectedTab = tab.getPosition();
if (selectedTab == 0) {
SalesMainScreen salesScreen = new SalesMainScreen();
ft.replace(R.id.content, salesScreen);
}
else if (selectedTab == 1) {
ClientMainScreen clientScreen = new …Run Code Online (Sandbox Code Playgroud) 我正在将一些旧的Objective-C代码转换为Swift,所以我可以放弃一些不赞成使用的方法,但是我一直在崩溃,到目前为止我似乎无法弄清楚是什么导致了它.我从P12证书中获取私钥,这个方法似乎工作正常,直到我到达实际需要从CFArray获取字典的部分,即使数组中有值,应用程序也会崩溃.这是我的代码:
func privateKeyFromCertificate(p12Name: String, withPassword password: String) -> SecKeyRef {
let resourcePath: String = NSBundle.mainBundle().pathForResource(p12Name, ofType: "p12")!
let p12Data: NSData = NSData(contentsOfFile: resourcePath)!
let key : NSString = kSecImportExportPassphrase as NSString
let options : NSDictionary = [key : password]
var privateKeyRef: SecKeyRef? = nil
var items : CFArray?
let securityError: OSStatus = SecPKCS12Import(p12Data, options, &items)
let description : CFString = CFCopyDescription(items)
print(description)
if securityError == noErr && CFArrayGetCount(items) > 0 {
let objects : CFDictionaryRef = CFArrayGetValueAtIndex(items, 0) as! CFDictionaryRef …Run Code Online (Sandbox Code Playgroud)