我有问题.我遵循了很多指南,但仍然无法让我的Share按钮工作.我在ActionBar中显示了图标,但是当我按下时没有任何事情发生在android:showAsAction ="always".但是当android:showAsAction ="never"时它会起作用.我只想让分享图标始终显示在ActionBar中.我做错了什么?请帮忙
这是我的代码:
public class Main extends Activity {
private ShareActionProvider mShareActionProvider;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem item = menu.findItem(R.id.shareButton);
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.shareButton:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Check it out";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
return true;
case R.id.aboutButton:
Intent intent = new Intent(this, About.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
} …Run Code Online (Sandbox Code Playgroud) 我是iOS编程新手,现在我遇到了问题.
有一个登录屏幕用于[self presentViewController:loginview animated:YES completion:nil];在MasterViewController中显示它.
现在我想在之后调用一个方法(重新加载数据) [self dismissViewControllerAnimated:YES completion:nil]
这是我的代码:
[self dismissViewControllerAnimated:YES completion:^ {
[self getPostData]; // Reload Data
[self.tableView reloadData]; // Reload Data
}];
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
(重载方法在MasterViewController中)
有人可以帮帮我吗?
所以这是字符串s:
"Hi! How are you? I'm fine. It is 6 p.m. Thank you! That's it."
Run Code Online (Sandbox Code Playgroud)
我希望它们被分隔为一个数组:
["Hi", "How are you", "I'm fine", "It is 6 p.m", "Thank you", "That's it"]
Run Code Online (Sandbox Code Playgroud)
这意味着分隔符应为". "+ "? "+"! "
我试过了:
let charSet = NSCharacterSet(charactersInString: ".?!")
let array = s.componentsSeparatedByCharactersInSet(charSet)
Run Code Online (Sandbox Code Playgroud)
但它也将分为p.m.两个元素.结果:
["Hi", " How are you", " I'm fine", " It is 6 p", "m", " Thank you", " That's it"]
Run Code Online (Sandbox Code Playgroud)
我也试过了
let array = s.componentsSeparatedByString(". ") …Run Code Online (Sandbox Code Playgroud) 我想知道我们如何在Swift中使用sort或sorted运行多维数组?
例如他们的数组:
[
[5, "test888"],
[3, "test663"],
[2, "test443"],
[1, "test123"]
]
Run Code Online (Sandbox Code Playgroud)
我想通过第一个ID从低到高排序:
[
[1, "test123"],
[2, "test443"],
[3, "test663"],
[5, "test888"]
]
Run Code Online (Sandbox Code Playgroud)
那我们怎么做呢?谢谢!
我想popoverPresentationController在用户点击iPad中的单元格时显示.这是我的代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(indexPath.section == 0){
if(indexPath.row == 0){
let textToShare = NSLocalizedString("SHARE_MESSAGE", comment: "Message...")
if let appStoreURL = NSURL(string: "http://www.google.com/") {
let objectsToShare = [textToShare, appStoreURL]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
if let popView = activityVC.popoverPresentationController {
let v = tableView as UIView
popView.sourceView = v
popView.sourceRect = v.bounds
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这在iPad上是错误的(屏幕上没有显示).那我怎么解决呢?
PS:这是UIButton的代码,它在iPad上工作正常(在屏幕上显示):
@IBAction func shareButtonAction(sender: AnyObject) {
let textToShare = …Run Code Online (Sandbox Code Playgroud) 目前,我有两个表视图控制器,包含一些相同的自定义tableview单元格.每个表视图控制器都有自己的自定义tableview单元格.我希望只创建一个自定义表视图单元格,可以在这两个表格视图控制器之间共享.我可以参考任何指南吗?
我想UIRequiredPassowrdViewController从另一个视图中停止一个 NSTimer SettingsTabelViewController,所以我首先创建倒计时:
class UIRequiredPassowrdViewController: UIViewController, UITextFieldDelegate {
var timer: NSTimer?
var remainingSeconds = 1000
override func viewDidLoad() {
super.viewDidLoad()
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "updateTimer:", userInfo: nil, repeats: true)
}
func updateTimer(timer: NSTimer) {
remainingSeconds -= 1
println(remainingSeconds)
}
func StopTimerNotication(){
println("Function Start!")
timer?.invalidate()
timer = nil
}
}
Run Code Online (Sandbox Code Playgroud)
然后我StopTimerNotication()从另一个角度调用函数SettingsTabelViewController:
@IBAction func myButtonClicked(sender: AnyObject) {
println("Button Clicked")
var myClass: UIRequiredPassowrdViewController=UIRequiredPassowrdViewController()
myClass.StopTimerNotication()
}
Run Code Online (Sandbox Code Playgroud)
我运行应用程序,日志显示正确倒计时,单击按钮并运行该功能,但计时器只是没有停止:
999
998
997
996
995
994
993
992 …Run Code Online (Sandbox Code Playgroud) 例如,我想要数组
["ABC", "ADE", "BCD", "HYD", "ZYX", "ZZZ"]
Run Code Online (Sandbox Code Playgroud)
转换为:
[
["ABC", "ADE"],
["BCD"],
["HYD"],
["ZYX", "ZZZ"],
]
Run Code Online (Sandbox Code Playgroud)
那么我该如何实现呢?谢谢!
救命!
我是XCode的新手,现在我遇到了一个问题.
当我在应用程序中使用以下代码并创建一个新的ViewController类LoginViewController时.
在iPhone中,该应用程序运行良好.但是当我在iPad上测试它崩溃并在日志中显示以下内容:
2014-05-06 17:05:31.289 We Love HK[38711:60b] -[LoginViewController viewControllers]: unrecognized selector sent to instance 0x10942c3d0
2014-05-06 17:05:31.291 We Love HK[38711:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LoginViewController viewControllers]: unrecognized selector sent to instance 0x10942c3d0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001019fc495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010175b99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101a8d65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001019edd8d ___forwarding___ + 973
4 CoreFoundation 0x00000001019ed938 _CF_forwarding_prep_0 + 120
5 We Love HK …Run Code Online (Sandbox Code Playgroud) ios ×6
swift ×6
arrays ×2
objective-c ×2
android ×1
cocoa-touch ×1
ipad ×1
nstimer ×1
share-button ×1
sorting ×1
split ×1
string-split ×1
uitableview ×1
xcode ×1