如何js获取button文字上的文字

1.问题一个button,点击事件实现在一个搜索图标和“取消”之间的转换,那需要在响应事件中判断标题文字,所以我想获取button的标题&代码如下:
if ([button.titleLabel.text isEqualToString:@&取消&]) {
[button setTitle:@&& forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@&search_normal&] forState:UIControlStateNormal];
[button setTitle:@&取消& forState:UIControlStateNormal];
[button setImage:nil forState:UIControlStateNormal];
}问题来了,判断无效。即我设置title为@”“时,判断&span style=&font-family: Arial, Helvetica, sans-&&[button.titleLabel.text isEqualToString:@&取消&]&/span&依旧成立。2.说明看了一眼UIButton的类,才发现事情不能想当然的认为。因为为button赋值title实际上是将值赋给了currentTitle。所以代码应该如是写:
if ([button.currentTitle isEqualToString:@&取消&]) {
[button setTitle:@&& forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@&search_normal&] forState:UIControlStateNormal];
[button setTitle:@&取消& forState:UIControlStateNormal];
[button setImage:nil forState:UIControlStateNormal];
}3.同理其他的赋值及获取值都可以看一下就一目了然- (void)setTitle:(NSString *)title forState:(UIControlState)
// default is nil. title is assumed to be single line- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default if nil. use opaque white- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil. use 50% black- (void)setImage:(UIImage *)image forState:(UIControlState)
// default is nil. should be same size if different for different states- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state NS_AVAILABLE_IOS(6_0); // default is nil. title is assumed to be single line- (NSString *)titleForState:(UIControlState)
// these getters only take a single state value- (UIColor *)titleColorForState:(UIControlState)- (UIColor *)titleShadowColorForState:(UIControlState)- (UIImage *)imageForState:(UIControlState)- (UIImage *)backgroundImageForState:(UIControlState)- (NSAttributedString *)attributedTitleForState:(UIControlState)state NS_AVAILABLE_IOS(6_0);// these are the values that will be used for the current state. you can also use these for overrides. a heuristic will be used to// determine what image to choose based on the explict states set. For example, the 'normal' state value will be used for all states// that don't have their own image defined.@property(nonatomic,readonly,retain) NSString *currentT
// normal/highlighted/selected/disabled. can return nil@property(nonatomic,readonly,retain) UIColor
*currentTitleC
// normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1)@property(nonatomic,readonly,retain) UIColor
*currentTitleShadowC
// normal/highlighted/selected/disabled. default is white(0,0.5).@property(nonatomic,readonly,retain) UIImage
// normal/highlighted/selected/disabled. can return nil@property(nonatomic,readonly,retain) UIImage
*currentBackgroundI
// normal/highlighted/selected/disabled. can return nil@property(nonatomic,readonly,retain) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0);
// normal/highlighted/selected/disabled. can return nil一个cell有一个button,如何点击这个button获取对应cell的文字 - 开源中国社区
当前访客身份:游客 [
当前位置:
问题是这样的,我有个tableview,里面有图片,文字! 每个cell有个button &我要点击这个button取出这些文字与图片。有什么方法,或者逻辑!求大神分析,如图......怎样点击 &分享 &获取每个cell对应的文字
共有6个答案
<span class="a_vote_num" id="a_vote_num_
能说的清楚点吗,获取到你要的数据,要在程序里用,还是你想做一个点击分享按钮就把状态分享到微信或者微博的功能?
<span class="a_vote_num" id="a_vote_num_
方法有很多.比如你可以用button.superView来获取它的父视图,具体我不知道你将button添加在了哪个视图上.如果不是添加在这个视图上的话可以接着往后面加superView来获取cell.获取到了cell上面的东西不就是想拿什么拿什么么.
<span class="a_vote_num" id="a_vote_num_
cell初始化时候 给它初始化block 返回值可以是点击的行数或者cell的数据源对应的下标,找到对应的cell或者直接取数据源中的值,就可以实现了
<span class="a_vote_num" id="a_vote_num_
将cell的每一行作为button的tag 点击button 取相应cell的东西就可以了
<span class="a_vote_num" id="a_vote_num_
#pragma mark -- 关注按钮事件
-(void)attentionBtnAction:(UIButton *)attentionBtn {
& & if (self.num == 0) {
& & & & FocusTableViewCell *cell = (FocusTableViewCell *)attentionBtn.superview.superview;
& & & & NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
& & & & FocusModel *model = self.attentionDataSource[indexPath.row - 4];
& & & & self.indexPath = indexPath.row;
<span class="a_vote_num" id="a_vote_num_
以上是主要代码
更多开发者职位上
有什么技术问题吗?
进击的i...的其它问题1947人阅读
Graphics2D&& g2d&& =& (Graphics2D) new Robot().createScreenCapture(&&&&&&&&&&&&&& new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())).getGraphics(); Font f = new Font(&Serif&, Font.BOLD, 40);String text =&any language is OK&;double len = 0;g2d.drawString(text&& ,&& 0,&& 0);&& FontRenderContext&& context&& =g2d.getFontRenderContext();Rectangle2D&& bounds=f.getStringBounds(text,context); len = bounds.getWidth();
&input type=&button&& style=&Word-Wrap=word-break:break-width:30&& value=&这时候word-warp不管用&#13;后换行& &
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:99368次
积分:1301
积分:1301
排名:千里之外
原创:29篇
(1)(9)(6)(6)(3)(1)(1)(5)> 对不起!您查找的页面在火星,地球暂时无法访问
内部服务器错误(Internal Server Error)
秒之后页面自动跳转,您可以:
2) 去其他地方逛逛:   webview中如何捕获js的button点击事件, 怎么在button点击之后获得js输入框中的字符串
&来源:读书人网&【读书人网():综合教育门户网站】
webview中怎么捕获js的button点击事件, 如何在button点击之后获得js输入框中的字符串?最近做webView的东东
webview中怎么捕获js的button点击事件, 如何在button点击之后获得js输入框中的字符串?最近做webView的东东遇到问题没解决,请教各位:webview中怎么捕获js的button点击事件, 如何在button点击之后获得js输入框中的字符串?[解决办法]/panyum/archive//2455456.html这是我以前做过的,你看看,把上面的文本框换成按钮就可以了[解决办法]另外获得文本框上面的字符串,也是同理的,在JavascriptInterface的方法里面,加上参数就可以了,例如:文中的 public void getDateTime(),你可以改成 public void getDateTime(String data),然后调用的时候,onclick=&window.ProxyBridge.getDateTime('数据');&将参数传入,这个和回调函数很相似的,至于获得文本框上的字符串,这个JS代码很简单的}

我要回帖

更多关于 js获取button文字 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信