我正在使用addTarget:action:forControlEvents,如下所示:
[newsButton addTarget:self
action:@selector(switchToNewsDetails)
forControlEvents:UIControlEventTouchUpInside];
我想将参数传递给我的选择器"switchToNewsDetails".我成功的唯一方法是通过写入来传递(id)发件人:
action:@selector(switchToNewsDetails:)
但我试图传递整数值之类的变量.以这种方式编写不起作用:
int i = 0;
[newsButton addTarget:self
action:@selector(switchToNewsDetails:i)
forControlEvents:UIControlEventTouchUpInside];
以这种方式编写它也不起作用:
int i = 0;
[newsButton addTarget:self
action:@selector(switchToNewsDetails:i:)
forControlEvents:UIControlEventTouchUpInside];
任何帮助,将不胜感激 :)
我正在尝试<div>在用户更改a的值时更改标记的显示CSS属性<select>.
这是我的HTML代码:
<select type="text" name="category" onblur="display_hidden_fields();">
<option><!-- Content --></option>
<option><!-- Content --></option>
</select>
<div id="hidden" style="display:none;">
<label for="test">Label</font></label>
<select type="text" name="test">
<option value="1">Default</option>
<option value="2">Value1</option>
<option value="3">Value2</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
(注意:这是我的代码的简化版本.其实,每一个<label>和<select>在<td>.我认为这并不重要)
现在,我的JS代码:
function display_hidden_fields()
{
alert("JS Function");
document.getElementById("hidden").style.display = "block";
}
Run Code Online (Sandbox Code Playgroud)
好.当我<option>在第一个<select>命名的"类别"中选择一个新的时,我得到警告"JS功能".所以我的display_hidden_fields()功能正确执行.
但是这个功能的第二行确实......没有!我的<div>名字"隐藏"没有显示:(
在我看来,我的代码没有任何问题.而且,我尝试了很多变种.
- style="display:block"在<div>属性中指定,并在JS中将其更改为"none".
- 或尝试使用其他属性,如"内联","内联块",...
- 或使用"可见性"而不是"显示"
- 或者不在HTML中指定任何属性.
有人能帮帮我吗?:)
谢谢.
我想我找到了一些有趣的东西.它似乎<div>与display:none;混合 …
我试图使用initWithContentsOfURL:encoding:error:像这样:
NSURL *url = [[NSURL alloc] initWithString:@"http://my_url.com/my_file.xml"];
NSError *error = nil;
NSString *my_string = [[NSString alloc] initWithContentsOfURL:url
encoding:NSUTF8StringEncoding
error:&error];
我得到一个空的my_string变量.
我尝试了initWithContentsOfURL:方法(在iOS 2.0中已弃用),我得到了我的页面内容.但我仍然需要指定一种编码语言.
怎么了 ?
谢谢 :)
我正在尝试更新viewWillTransition(to size: with coordinator:)iPhoneX 的方法.但是我无法获得safeAreaInsets值的目标.请帮忙!
override func viewWillTransition(to size: CGSize,
with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
if #available(iOS 11.0, *) {
if let window = UIApplication.shared.keyWindow {
let insets = window.safeAreaInsets
contentFrame = CGRect(x:insets.left, y:insets.top,
width:size.width - insets.left - insets.right,
height:size.height - insets.top - insets.bottom)
}
} else {
contentFrame = CGRect(x:0,y:0,width:size.width, height:size.height)
}
self.updateViews()
}
Run Code Online (Sandbox Code Playgroud) 我想在ListView中显示新闻(来自RSS).我已经成功创建了ListView,正确显示了标题和描述.但是我无法从URL显示图像.
这是我的代码:
maListViewPerso = (ListView) findViewById(R.id.listviewperso);
ArrayList <HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
int i = 0;
while (i < 55)
{
map = new HashMap<String, String>();
map.put("titre", newsArray[i]);
map.put("description", newsArray[i+1]));
map.put("img", newsArray[i+4]);
listItem.add(map);
i += 5;
}
SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem,
R.layout.affichageitem, new String[] {"img", "titre", "description"},
new int[] {R.id.img, R.id.titre, R.id.description});
maListViewPerso.setAdapter(mSchedule);
Run Code Online (Sandbox Code Playgroud)
你可以猜到,newsArray[i+4]包含我的图像的URL.
我写了一个函数drawable_from_url,它返回一个android.graphics.drawable.Drawable并且工作正常.我试着写这个:
map.put("img", String.valueOf(drawable_from_url(newsArray[i+4], "newsPic")));
Run Code Online (Sandbox Code Playgroud)
但它也没有工作(没有显示图像).价值的一个例子
String.valueOf(drawable_from_url(newsArray[i+4], "newsPic"))
可能是
android.graphics.drawble.BitmapDrawable@481f16d0
任何的想法 ?
谢谢.
我试图ViewController从另一个初始化.这是我第一次编写的代码ViewController:
#import "MediasVideosViewController.h"
@interface MediasViewController : UIViewController <UIWebViewDelegate>
{
NSArray* videosList;
MediasVideosViewController *mediasVideosViewController;
}
@property (nonatomic, retain) NSArray* videosList;
@property (nonatomic, retain) MediasVideosViewController* mediasVideosViewController;
Run Code Online (Sandbox Code Playgroud)
if (self.mediasVideosViewController == nil)
{
MediasVideosViewController* mediasVideos = [[MediasVideosViewController alloc] initWithNibName:@"MediasVideosView" bundle:nil];
self.mediasVideosViewController = mediasVideos;
self.mediasVideosViewController.videosList = self.videosList;
[mediasVideos release];
}
NSDate *start = [NSDate date];
[mediasVideosViewController.view addSubview:nil];
NSLog(@"adding nil to mediasVideosViewController.view took %f seconds", [[NSDate date] timeIntervalSinceDate:start]);
Run Code Online (Sandbox Code Playgroud)
将nil添加到mediasVideosViewController.view需要4.261444秒
真的吗?超过4s加nil mediasVideosController?它在1s和5s之间摇摆.
但如果我删除这一行:
self.mediasVideosViewController.videosList = self.videosList;
Run Code Online (Sandbox Code Playgroud)
从MediasViewController.m,我得到一个非常短的加载时间,如:
添加nil到mediasVideosViewController.view花了0.007613秒
它让我疯狂... …
我有一个UIWebView,它已经被我的请求(loadRequest)填充.
我想在其中添加一个UIButton.编写这个简单的代码很容易:
[self.myWebView loadRequest:request];
[self.myWebView addSubview:myButton];
Run Code Online (Sandbox Code Playgroud)
但是,似乎UIButton不会滚动UIWebView的内容.它像UIWebView顶部的层一样保持固定.因此,当用户滚动时,UIButton与内容不同步.
有任何想法吗 ?
我的视图可以在 iPhone 6 屏幕上正确显示,但需要在 iPhone 5 屏幕上滚动。我正在尝试更改一些自动布局约束,以消除在后者上滚动的需要。
前两张截图是 iPhone 6 和 iPhone 5 上的现有情况。第三张截图是我想要实现的目标(仅在 iPhone 5 上)。
我编写了以下自动布局约束,但我在这里遗漏了一些内容:
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=25,<=50)-[blueView]-(>=25,<=50)-[redView]-5-|"
options:0
metrics:nil
views:nameMap]];
Run Code Online (Sandbox Code Playgroud)
这里应该涉及拥抱和/或抗压吗?以什么方式?
编辑以显示更多我的实际代码:
[self addSubview:loginNSignupScrollView]; [self.loginNSignupScrollView addSubview:logoImageView]; [self.loginNSignupScrollView addSubview:horizontalScrollView]; [self.loginNSignupScrollView addSubview:appVersionLabel]; [self.horizontalScrollView addSubview:loginView];[self addConstraints:[NSLayoutConstraintconstraintWithVisualFormat:@"V:|[loginNSignupScrollView]|" 选项:0 指标:无 视图:nameMap]];
[self addConstraints:[NSLayoutConstraintconstraintWithVisualFormat:@"V:|[loginView(==350)]" 选项:0 指标:无 视图:nameMap]];
[self addConstraints:[NSLayoutConstraint约束WithVisualFormat:@"V:|-(>=30,<=60)-[logoImageView(==35)]-(>=25,<=50)-[horizontalScrollView]-30-[应用程序版本标签]-5-|” 选项:0 指标:无 视图:nameMap]];
[self addConstraint:[NSLayoutConstraint约束WithItem:self.horizontalScrollView 属性:NSLayoutAttributeHeight 相关者:NSLayoutRelationEqual 目标项目:自己 属性:NSLayoutAttributeHeight 乘数:0.0 常数:350]];
我目前正在开发一个网站.用户可以发布添加到数据库中的广告.我想在超过60天的时候删除这些广告.为此,我将编写一个PHP脚本,用于查找此类广告并从数据库中删除它们.
对,这很容易.但是如何在我的浏览器中每天不加载页面的情况下执行此脚本?我如何要求我的服务器定期自动执行它?
谢谢 !
PS:我在共享服务器上,而不是专用服务器上.它是否会使cron使用不可能?
iphone ×5
objective-c ×5
ios ×4
cocoa-touch ×2
addsubview ×1
android ×1
autolayout ×1
css ×1
html ×1
iphone-x ×1
javascript ×1
php ×1
swift ×1